Forum: C++ 4 Days Ago |
| Replies: 2 Views: 168 I suppose because containers are the most prominent and easy-to-explain examples when it comes to introducing templates - its probably safe to say that you'll encounter a vector very early on in your... |
Forum: C++ 4 Days Ago |
| Replies: 11 Views: 334 I would consider the 'safer' way to be to ditch the array and go with an STL container such as a vector. In fact, a std::vector is often nicknamed a "C++ Array".
They're automatically initialised... |
Forum: C++ 6 Days Ago |
| Replies: 2 Views: 182 Edit - Never mind, I didn't read the OP correctly |
Forum: C++ 6 Days Ago |
| Replies: 2 Views: 182 You can do exactly the same as you have described for your statically allocated array, then create a new smaller array and copy all of your remaining elements to it (This is an inefficient and... |
Forum: C++ Jan 5th, 2009 |
| Replies: 11 Views: 855 No offense nor insults intended at all. I merely assumed from your post that you had not read some of the highly acclaimed books from the likes of Sutter, Meyers, Alexandrescu, etc. If i'm... |
Forum: C++ Jan 4th, 2009 |
| Replies: 11 Views: 855 Even Stroustrup himself wouldn't say that. There are many really excellent C++ books floating around (of which TCPPPL is just one). If the only book you've ever read on C++ is that one, then... |
Forum: C++ Jan 3rd, 2009 |
| Replies: 15 Views: 640 In the latest code you posted, you're using the case keyword after an if statement. case is intended to be used in conjunction with switch, and is meaningless on its own.
Perhaps you could also... |
Forum: C++ Jan 3rd, 2009 |
| Replies: 11 Views: 1,044 Why do they need to have names at all? isn't it simply enough to be able to store un-named atoms in a vector and be able to find them using their position/index within the vector?
The "names"... |
Forum: C++ Jan 3rd, 2009 |
| Replies: 11 Views: 573 There's a bit of a nasty trick you can perform with arrays and references which can mimic the effect of modifying different data members of a class/struct at runtime.
Given a simple struct like... |
Forum: C++ Jan 3rd, 2009 |
| Replies: 1 Views: 222 There's plenty of ways around the many problems associated with cin >>; IMHO the best way to avoid them is to never use the >> operator in conjunction with cin in the first place (unless its really... |
Forum: C++ Dec 28th, 2008 |
| Replies: 2 Views: 8,037 Have you made any changes to the fill_pair() member function?
The mapmaker class relies on compile-time recursion to populate an array of "pairs". I wonder if any modifications you may have... |
Forum: C++ Dec 11th, 2008 |
| Replies: 1 Views: 252 You're presumably trying to call your function called search() but you also have a local variable called search too. The compiler doesn't understand, and thinks you're referring to that variable. ... |
Forum: C++ Nov 30th, 2008 |
| Replies: 4 Views: 444 No it isn't, the compile error was a simple typing mistake. |
Forum: C++ Nov 30th, 2008 |
| Replies: 4 Views: 444 Look very closely at this line dynarray(const dynarrray &ob);
I believe you probably meant to type dynarray instead |
Forum: C++ Nov 30th, 2008 |
| Replies: 5 Views: 422 Noone will spoonfeed you any solutions. have a good attempt at the problem for yourself and come back if you get stuck on anything along with a description of whatever it is you need help with,... |
Forum: C++ Nov 30th, 2008 |
| Replies: 21 Views: 1,691 It sounds as if you need to set up some accessor/modifier methods within your account class, rather than attempting to access them directly from your bank member functions. private data members of... |
Forum: C++ Aug 12th, 2008 |
| Replies: 4 Views: 811 Presumably you're already passing the array in as a parameter, so returning it is a little pointless (The original will be modified anyway, since arrays are always passed by-pointer to a function).
... |
Forum: C++ Aug 12th, 2008 |
| Replies: 4 Views: 375 A pointer is an object which represents an address in memory.
A reference is just a 'nickname' or 'alias' for an existing object.
I'm not going to go into any further detail since the nature of... |
Forum: C++ Aug 9th, 2008 |
| Replies: 6 Views: 940 A few comments
- When handling dynamically allocated memory in C++, you should use the new operator. Malloc is bad, since all it does is allocate memory on the heap - if you're creating an... |
Forum: C++ Aug 3rd, 2008 |
| Replies: 8 Views: 826 I'd be willing to bet that the vast majority of C++ developers rarely touch the Windows API directly. Even if you limit that group to just those who even develop applications for Windows... |
Forum: C++ Aug 3rd, 2008 |
| Replies: 4 Views: 1,163 You mentioned that you attempted a return type of Tree<T>::Node, However, that's not sufficient for the compiler to take your word for it that Node is indeed a type identifier and not something else.... |
Forum: C++ Aug 3rd, 2008 |
| Replies: 1 Views: 518 Why don't you try it for yourself and find out? If the compiler doesn't complain, then you know its ok
The only point where your compiler might produce an error, is if you attempt to compile... |
Forum: C++ Jul 28th, 2008 |
| Replies: 9 Views: 1,441 I'm not sure what language that is, but its not C or C++, unless the contents of "resource.h" happen to be an extremely nasty set of macros and #define statements.
If we knew what was inside... |
Forum: C++ Feb 10th, 2008 |
| Replies: 2 Views: 496 I assume you're after an IDE aswell, or do you intend to use a plain text editor (such as Notepad)? I also assume you're running Windows. If you're running linux, you're already equipped with... |
Forum: C++ Feb 10th, 2008 |
| Replies: 4 Views: 3,389 Assuming you're supposed to write your own, rather than use the standard C++ sort function, You'll need to implement a sort algorithm. a bubble sort or a selection sort should be fairly easy to... |
Forum: C++ Feb 9th, 2008 |
| Replies: 6 Views: 2,871 it would appear that your plist is empty at the point where your debugger has reached that portion of code.
You might prefer to use the deque::at() function, which is bounds checked, and throws an... |
Forum: C++ Feb 9th, 2008 |
| Replies: 6 Views: 2,871 In which case, the message may be telling you that you're attempting to de-reference the end() iterator (Which is actually 'one past the end'). To prevent the overflow problem, you might consider... |
Forum: C++ Feb 9th, 2008 |
| Replies: 6 Views: 2,871 The only problem I can see with your code is that eit2 will overflow, being one step in front of eit1 each time. I can't see anything which looks like it should give a compiler error. Could... |
Forum: C++ Jan 8th, 2008 |
| Replies: 3 Views: 2,314 The page appears to be over 10 years old, and the information probably older than that. Standard C++ does not have a class called ostrstream, and, to my knowledge, the standard C++ stringstream... |
Forum: C++ Dec 24th, 2007 |
| Replies: 3 Views: 823 The alternative, using the <map> library, if you'd prefer to give the orders a 'Key' value identifier
#include <map>
/* ... */
std::map< std::string, order > the_orders;
order my_order;... |
Forum: C++ Dec 20th, 2007 |
| Replies: 13 Views: 2,349 I think he asked for 250 miliseconds didn't he? not 25?
Anyway, it shouldn't matter, because there's no guarantee that CLOCKS_PER_SEC is equal to 1000 (I believe on POSIX systems its defined as... |
Forum: C++ Dec 19th, 2007 |
| Replies: 14 Views: 4,060 main returns an int because the standard says it returns an int. if you omit the int return type from main then some compilers will complain and not compile at all, others might allow it to compile... |
Forum: C++ Dec 18th, 2007 |
| Replies: 10 Views: 1,135 I think he means 'Dynamic Memory Allocation' - I could be wrong though. Either way, it works fine with both char and int |
Forum: C++ Dec 18th, 2007 |
| Replies: 12 Views: 1,223 If you were asked in another interview, which words would you remove from the English language, and why, how might you answer?
Then ask yourself what you think people who spoke the language would... |
Forum: C++ Dec 16th, 2007 |
| Replies: 3 Views: 1,765 Additional:
It seems I was half-right, although, the STL uses the std::less<T> functor class as its default predicate for sorted containers, as found in the <functional> header. (std::less in... |
Forum: C++ Dec 16th, 2007 |
| Replies: 3 Views: 1,765 I could be mistaken, though I believe that the STL sorted containers expect a type with a valid operator<. If the type doesn't provide one, then overloaded constructor(s) will take an additional... |
Forum: C++ Dec 15th, 2007 |
| Replies: 12 Views: 1,245 The best tip I can think of with regard to writing templated code, is to write a non-template version first. Then you can be sure that your program is correct for one type (such as int), and that... |
Forum: C++ Dec 8th, 2007 |
| Replies: 2 Views: 4,478 If you're able to split each 'word' into separate strings, then you're already half way there
use the toupper function on the first character of that word, to generate the uppercase equivalent of... |
Forum: C++ Dec 7th, 2007 |
| Replies: 3 Views: 1,215 The >> operator skips over whitespace automatically.
One alternative could be to capture each line of input from the file individually as a string, using the getline function.
std::string... |
Forum: C++ Dec 6th, 2007 |
| Replies: 3 Views: 899 There's no such thing as a "Best" sorting algorithm. Depending on the amount of data you're holding, and how ordered the data is to start with, one algorithm may be better than the other in... |