2,898 Posted Topics
Re: You need to make the destructor in the base class as virtual (otherwise the base class destructor will be called directly). Try this code: [CODE] #include <iostream> class base1 { public: virtual ~base1() { //notice virtual keyword here std::cout << "base1 destructor called!" << std::endl; }; }; class derived1 : … | |
Re: The problem is that calling "cin >> ch;" will wait for the enter to be pressed, then will read the first char. This will leave the newline or '\n' character on the input stream, so the next time you do gets() to read the line, it will grab the '\n' … | |
Re: Well, I agree with jonsca, use a while loop. You can also use "continue" to come back to the start of the while loop from anywhere inside the loop. If it really is not going to work with a while loop, do everything you can think of to make it … | |
Re: Well, I think tesuji answered pretty well, but if I may add something to answer your original question: >>should I use some RDBMS or should I just write some stucts or better yet classes that relate to each other through some methods and then write them to a binary file? … | |
Re: Line 17, 24, 33 are all the same and they are all wrong for one very important reason. "post_evaluation *t;" declares a pointer to a post_evaluation object, but it is not initialized. So "t" points nowhere or anywhere, which is really the same thing. You cannot use t if it … | |
Re: Your problem is with handlerthread. Are you sure that once a thread is started that it remains valid when going back to idle or when it is initially at idle? This seems to mean that the handlerthread pointer is destroyed, or its internal handle to the actual OS thread (pthread … | |
Re: Well "master mike" is back to quote tesuji... Your program crashes because of this portion of the code (line 40 to 52): [CODE] //For each i > j: row i - (Cij/Cjj)* row j i = j++; for(int row_i = i; row_i < N; row_i++) { for(int row_j = j; … | |
Re: @AkashL: The auto_ptr will help because it will make sure the "paramTime" in this case is deleted before main() exits, but it is not ideal because, as you said, it is not reference counted, so if the pointer is copied to other functions and stuff, it will get deleted at … | |
Re: Well, in the expression "const QMimeData* const", the first const means that the QMimeData is not changeable (constant) and the second const means that the pointer to it is not going to change either. If you don't need to change the pointer (i.e. create your own QMimeData object), then make … | |
Re: Well.. the error is very strange.. never seen that before. But the source of it is very easy to find: Your first two functions have a ";" before the opening braces! Two weird errors, two misplaced semi-colons. Also, where is the implementation for your constructor? And, you should not use … | |
Re: Wow! that's something creepy... trying this, it helps me understand why this is how it is: [CODE] int main(){ { int j=5; std::cout << ((++j) + (++j)) + (j++) << std::endl; } { int j=5; std::cout << ((++j) + (++j)) << std::endl; } { int j=5; int x = ++j; … | |
Re: Which is better for development? IDEs: I have to say windows just because either Borland or Microsoft IDEs are really full-featured, but also expensive. If money is an issue, then Linux has great tools too, KDevelop is now a pretty descent rival to Visual Studio or RAD Studio. General Programming … | |
Re: Don't let this blow your mind: [CODE] aReturnType some_function_name(aParameterType some_parameter, aReferencedType& some_ref_parameter) { aType some_variable(SOME_INITIAL_VALUE); for(anIterator some_iterator = some_start_value;some_iterator != some_end_value; ++some_iterator) some_variable += some_other_function_name(some_parameter, some_ref_parameter); return yet_another_function(some_variable); }; [/CODE] These are just phony names people use in text books to make examples (so is Foo and Bar, before you … | |
Re: >>error C2582: 'operator =' function is unavailable in 'Cord' This means there is no default assignment operator for type Cord, you need to implement one. This error would not happen in C++. RANT ALERT! This is C++/CLI, not C++. So you will probably find better luck looking for answers by … | |
Re: time.h does not support milliseconds, it is a C legacy library made for systems that "in general" cannot support more than seconds precision. Of course, modern computers do support milliseconds, and most often microseconds too. If your code is C, I believe there is no way. If in C++, there … | |
Re: [QUOTE]is it compulsary to write main fun in c and c++,can we only write 1 main fun.[/QUOTE] Well the main function is the entry point for the executable. Just a special function that the compiler knows should be the sort-of first implicit call to start the program. So if you … | |
Re: [QUOTE]At no time has floats ever been faster than doubles. [/QUOTE] Well... that's absolutely true, if you restrict the discussion to the CPU. But floats have always been very popular for efficiency reasons in game programming because GPUs are (or at least "were", in my days) designed with custom floats … | |
Re: Many bigger projects use building (compilation) tools such as cmake which select compilers based on the source file extensions, and .c would be passed to the C compiler. Some projects often use .c files (C code) as third-party sources for some special purposes such as hardware drivers and other IOs, … | |
Re: You should copy the data pointed to by d inside the Add function, because of this, from [url]www.cplusplus.com[/url] on string.c_str(): [QUOTE]The returned array points to an internal location with the required storage space for this sequence of characters plus its terminating null-character, but the values in this array should not … | |
Re: Well in "char* str="my name";" the _string_ "my name" is a list (or array) of characters (char) and "str" is a pointer to the first character in the list. So by incrementing the pointer "str" you get a pointer to the next character, then the next, and the next again, … | |
Re: 1. For C++, I would disagree with case 1 above, in this case you want to use a reference as in: [CODE] #include <iostream> //notice no .h here void change(int a) { a+=1; } void changeref(int& a) { //notice & instead of * a+=1; //notice no leading * } int … | |
Re: It seems quite alright to me! One tip: [CODE] //THIS: cin>>userIn;//get user input int loopLimit = atoi(userIn.c_str());//get the numberEntered //COULD BE JUST THIS: int loopLimit; cin>>loopLimit;//get user input [/CODE] | |
Re: Are you trying to write a SpyBot? I'm not going to be the one to help you with that... are you also trying to read the credit card numbers that people might be writing on other open windows, while they are "playing your game"... just joking! To be fair, I … | |
Re: Simplest program, the famous Hello World program: [CODE] #include <iostream> int main() { std::cout << "Hello World!" << std::endl; return 0; }; [/CODE] | |
Re: There is one naming convention that is used a bit and it's called Hungarian notation. I'm not sure of the exact format, but essentially it uses leading letters to indicates certain things, more or less like this: [CODE] class IAbstractClass { //notice "I" for abstract or interface or base classes. … | |
Re: Well I don't know what you imagine "x^y" to be supposed to do, but I can tell you what it does and why the compiler warns you about it. The ^ operator in C++ is a bitwise XOR operator, so x^y produces the results of x XOR y (XOR is … | |
Re: First off, I can't help on the AT side, but I know matlab pretty well. There are essentially two possibilities: either run in matlab and use DLLs to interface to C++ code to deal with AT commands and whatever else, or compile matlab using RTLab. So if you are in … | |
Re: Why do you need AddElement? the list already has functions to add (push_back), delete, insert, etc. All you need to take care of with the clsMyClass is make sure that all constructors work (and do not throw exceptions) and that you have proper copy-semantics, i.e., you need to implement a … | |
Re: Try to write a serialization library like [URL="http://www.boost.org/doc/libs/1_43_0/libs/serialization/doc/index.html"]this one[/URL]. That should keep you busy for a while, and help you learn advanced OOP concepts of C++ that may challenge you a bit. Also see [URL="http://www.boost.org/doc/libs/1_43_0/libs/spirit/doc/html/index.html"]these tutorials[/URL], they will show many nice ways of mixing template meta-programming and generic programming, that … | |
Re: Yes and no. This will create a different static variable in each .c you compile. To solve this, declare it as "extern" as well, this will tell the compiler to look for all other declarations of the same variable and "merge" them into a single one. Of course, if having … | |
Re: In MFC or any other GUI library, things are Event Driven which mean that the execution of the program is not your typical main_while_loop type of thing you find in procedural programming. Your application is simply reacting to events (handling) as they come, so your question is a bit bizarre, … | |
Re: I know how to fix your code, but to let you do it on your own, I will say this: the recursive formula (the second one) is used to compute each _term_ of the first equation one after the other. In your implementation, you use "result" in the recursive formula, … | |
Re: Well for small projects it ok to put everything in the header files, but as the project grows it will become more and more inconvenient. Since you have read stuff on C++ I will not repeat to much that the "philosophy" behind headers and cpps is to declare classes and … | |
Re: Look up SDL (cross-platform API like the Win32 API) or Qt (like MFC or other GUI libraries). | |
Re: C++ is the most flexible and universal language for programming. [URL="http://www2.research.att.com/~bs/applications.html"]Look at the list firstPerson posted[/URL]. It goes to show that virtually all games are in C++, virtually all serious scientific coding is in C++, all Microsoft apps too, virtually all kernel libraries of operating systems, etc. etc. One of … | |
Re: To match your very little effort at asking the question.. my answer is: std::sort (<algorithm> header). | |
Re: Well it looks like a good book, and gamedev is a good source for openGL game programming. Consider first going through the [URL="http://nehe.gamedev.net"]NeHe Tutorials[/URL], that's a great start for openGL rendering (but the advanced tutorials are a bit outdated, in the sense that better techniques exist today). About the book … | |
Re: First off, the line "TicTacToe game(char X,char E);" actually is interpreted by the compiler as a function declaration, so that is what the error message points. "game" is declared as function, as far as the compiler can tell. In any case, this is not valid syntax, as Dave pointed out. … | |
Re: These errors say that the compiler cannot find the definition (implementation) of the class CPlayer. You must have forgotten to add the Player.cpp file to the compilation process (or its .o file, or the static library to which it was compiled). | |
Re: >>treasure on each space line could be 3,2 or 1 but not 0. I don't understand that, but for the rest.. You can call rand() as many time as you want, so that solves the problem of having multiple treasures. Also, to avoid walls and borders and other treasures, just … | |
Re: Please post with code tags! This line in displayTotal: [CODE]for (int x = 0; x < 12; x =+ 1)[/CODE] Should be this:[CODE]for (int x = 0; x < 12; x += 1)[/CODE] Notice the += instead of =+ (this would mean "x = +1"). | |
Re: [QUOTE] Total of food: $2.87 Tax: $0.19 Total for order: $3.06 [/QUOTE] Man that's a cheap meal! What country do you live in where you can get a soda, burger and fries for 3 bucks at only 6% sales tax! Anyhow.. I think your code is fine and its almost … | |
Re: As it is now, the original string gets replaced by the sub-string, so you do get the sub-string back from the function. But if you want it like you said. First you need to allocate new memory for the sub-string, with the right size (n2 + 1). Then you write … | |
Re: Well this is one problem with: [CODE] priority_queue<Job,vector<Job*>,less<vector<Job*>::value_type> > event_list; [/CODE] In this case, vector<Job*>::value_type is essentially equal to Job* (not exactly, but no need to worry about the difference). Then, now less<Job*>, really means that the elements will be sorted by the comparison "a < b" where a and … | |
Re: That's nasty.. I hate VC++! I think you must be missing some headers, or at least VC++ doesn't find them.. these things are hard to find by yourself, especially since VC++ is probably the compiler with the least useful error messages (no back-tracing!). What I do in these cases, I … | |
Re: This means that the compiler cannot find the definition of the function calcCelsius that matches the prototype: [CODE] void calcCelsius(double); // the "_cdecl" thing is just the default calling convention. [/CODE] So either you didn't provide a definition for that function, or your definition doesn't match the prototype exactly, or … | |
Re: As suggested by firstPerson, class or function templates are typically the best way to achieve common functionality for different types. So you can look up templates for info on that. Also, operator or function overloading can make the code more uniform (as in the above, your functions don't need to … | |
Re: It looks a bit to me, from your class names, that defining your own namespaces might be a good option for you to consider instead of nested classes.. just a suggestion. | |
Re: Your prototype and your definition should always match EXACTLY, that is true for functions and everything else. Since the point of the prototype is to tell the rest of the code exactly how the function, that is defined later, should be called, so it is meaningless if the definition does … | |
Re: Well first, you say (wrist, elbow, shoulder, etc.) so I guess what you have to start with is not the actual position and orientation of each part of the body, but the position of each joint of the body. Since parts are between joints, you need to transform those joint … |
The End.