2,898 Posted Topics
Re: SDL is written in C, so I very much doubt that anything is derived from anything since inheritance in not possible in C. And, yes, SDL_surface is a structure, here is [URL="http://sdl.beuc.net/sdl.wiki/SDL_Surface"]the doc[/URL]. Very often (but not always), you should treat SDL_surface pointers and any other pointers from SDL as … | |
Re: You should check out two libraries that are very nice for doing this, the [URL="http://www.boost.org/doc/libs/1_47_0/doc/html/program_options.html"]Boost.Program-Options[/URL] and the [URL="http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/index.html"]Boost.Serialization[/URL]. | |
Re: It is quite easy to check the validity with C++'s formatted input mechanism, which will fail if the input is not of the required format. Personally, I don't like to fiddle around with the std::cin too much, so I would recommend the intermediate use of std::stringstream. Something like this would … | |
Re: It's a classic problem with class templates and friend functions. Basically, the problem is that the friend-function declaration declares a function, not a function template. So, when you instantiate the class [ICODE]List<int>[/ICODE], the compiler will instantiate all the member function declarations (not their definitions). The instantiation of the friend-function declaration … | |
Re: Disregard what Scholl-R-LEA just said. This loop is correct: [CODE] while (in_stream >> number) [/CODE] In fact, the above is the idiomatic way of reading from a file and it is correct. The operator >> does indeed return a reference to a istream, such that it can be chained. However, … | |
Re: What are you pushing on the stack? If you are just modifying what the char-pointer points to, then yeah, it will change all the stack entries. Try with std::string instead of char-pointers. As in: [CODE] int i = 0; int arraySize; std::string stack[100]; void stackPush(const std::string& pushed) { if(i == … | |
Re: The first version contains two overloaded functions (each being a function template). The second version is a template specialization for T = string. However, in your first version, there is no way to deduce the type T from the calling context of the second function template, so you will have … | |
Re: There's nothing wrong with that code. Try to post code that reproduces the error you are experiencing. | |
Re: Yes, of course. In KDevelop it is called a "session" which can contain as many projects as you like. I don't really know how to configure it and all since I use cmake for my build-configuration, which KDevelop supports very well. So, at least, when I am in KDevelop and … | |
Re: Didn't you think it was important to mention that C++ also implements the AND and OR operators as short-cut operators, that is, if evaluating the first expression is sufficient to get the result of the boolean operation, then the other operands are not computed. For example, here's a little question: … | |
Re: >>someone mentioned that there is a managed C++ that compiles first to Microsoft CLR. That is called C++/CLI. It is not really C++, it is a completely different programming language if you ask me (it is a kind of a frankenstein between C++ and C#). But I know little about … | |
Re: >>how many instances of the static test t are getting created. One. >>What will happen? Add this to your code: [CODE] if( ( &a.t == &a.t.t ) && ( &a.t.t == &a.t.t.t.t.t.t ) ) cout << "All test t instances are the same!" << endl; [/CODE] This is just due … | |
Re: The problem is not with what you are compiling but how you are compiling it. Please tell us how you compiled this code (what OS, what compiler, what compiler command or build configuration, etc.). EDIT: Oups, sorry, didn't notice the two pi variables. That's probably the problem. | |
Re: The [URL="http://www.cplusplus.com/reference/iostream/stringstream/"]stringstream[/URL] class is your best friend for this purpose. Use the getline() function to obtain the string for the entire line, then pass that string to a stringstream object and then extract the tokens from the stringstream. For dealing with multiple and variable-number of arguments, you can do what … | |
Re: Why don't you program your UI in C++ and with a cross-platform GUI tool, like [URL="http://qt.nokia.com/products/"]Qt[/URL]. Qt will work everywhere. You most probably want to do your Windows coding in GCC to make sure it will compile with no problems on other OSes. Also, focus on using cross-platform libraries for … | |
Re: I'm surprised Narue didn't catch this, I guess goddesses are not infallible... The error is due to the fact that you are trying to separate the function definitions from the function declarations of a class template. Templates are special in C++, they are not real compilable code, they are instructions … | |
Re: @shellexecutor: Don't bump 2 year old threads (the OP probably doesn't care anymore), and don't provide fully working code, especially for such a classic homework problem (pascal triangle) and when the OP didn't show much effort of his own. | |
Re: Its a linking error, you must have forgot one source file in the compilation. The error means that the function definitions are not found by the linker. Those should normally be in the source file that correspond to the header in which these functions are declared, but you need to … | |
Re: >>I don't know the major differences apart from headers and inputs and outputs should be replaced with cout << and cin >> Well. That's actually all you need to change to turn the code into C++ code. [CODE] #include <iostream> //this replaces stdio.h const int ROW = 4; const int … | |
Re: GCC does not fully support the multithreading libraries or language features yet. [URL="http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.200x"]See this[/URL]. The main problem is that the threading libraries make most sense when the language features for concurrent programming are also available, and these are probably the hardest of the new language features to implement. I recommend … | |
Re: Like sfuo said, the || and && operators are for boolean values, so, you need to put two conditions (or expressions that evaluate to a bool value) on the two sides of those operators. In this case [ICODE]while(random != 0 && random != 1)[/ICODE], which reads as "while 'random' is … | |
Re: ptr is a pointer to a pointer to a variable. That expression dereferences twice to get the actual variable. | |
Re: Why don't you read [URL="http://msdn.microsoft.com/en-us/library/ms686722(v=vs.85).aspx"]the instructions[/URL] yourself? | |
Re: It is important to remember that MACROs and #defines completely ignore namespaces and are thus very prone to name-clashes if used carelessly. So, the convention that is the most wide-spread in all C/C++ development is to use all uppercase for MACROs and #defines. This serves as a clear separation between … | |
Re: For GCC, you can compile with the options [ICODE]-pedantic-errors -std=c++98[/ICODE] to tell GCC to compile the code in strict standard C++ code (standard from 98, which is current) and to produce compilation errors if you do anything that is not strictly standard C++ code (i.e. pedantic). It is not a … | |
Re: >>Since small object allocation in heap is bad From the perspective of experience, allocating anything from heap memory is bad, whatever size it has. You only do it when it is required. It is required when the size or type is not known at compile-time, or if it's too big … | |
![]() | Re: The [URL="http://opencv.willowgarage.com/wiki/"]OpenCV[/URL] library can do this easily. It might be a bit of overkill since OpenCV is a lot more feature-rich than you need. Another alternative and very easy to use library is [URL="http://freeimage.sourceforge.net/"]FreeImage[/URL]. Also, if you have access to linux, either on your computer or your website's server machine, … ![]() |
Re: You bubble sort method is missing one nested loop level. The loop that you have will have the result of making the largest distance to end up at the end of the array (and thus the name "bubble" sort). But it _only_ takes the largest value to the end, all … | |
Re: >>will this work? Just try it: [CODE] void foo(int bar[], int sz) { for(int i = 0; i < sz; ++i) bar[i] = 42; }; int main() { int b[50]; foo(b,50); return 0; }; [/CODE] and yes, it works. | |
Re: This is a really weird error, and I'm sure there is something you are not telling us. My guess would be that the audioBuffer gets relocated. The fact that you reallocate or change the std::vector member (I assume is held by value in audioBuffer, as it should) should not cause … | |
[B]Beginner's guide to C++0x: Avoiding Memory Problems by Design of Ownership[/B] If you ever read any resources on C++ programming or object-oriented programming, you must have heard some rethorics like "inheritance is for the [I]is a[/I] relation, composition is for the [I]has a[/I] relation". Is that all? Is that the … | |
Re: An lvalue is defined as something that can appear on the left-hand-side of an assignment (like [ICODE]a = b;[/ICODE]). Basically, it needs to be a variable with a name, i.e., not a temporary or constant value (like [ICODE]5[/ICODE]). Certain operations, like the assignment operator, require that the variable you use … | |
Re: [URL="http://www.blender.org/"]Blender[/URL] is a pretty good editor and it supports many formats. The world of 3D file-formats is seriously lacking a wide-spread standard format. It used to be 3ds, when only 3D Studio Max existed as a decent editor. Now, there are many 3D editors, many formats, and most game-studios have … | |
Re: Post your code between the code tags [_CODE_] [_/_CODE_] (with no underscores). | |
Re: I'm no expert on audio/video streaming. On most of my projects, either other people dealt with that, or we had an off-the-shelf solution requiring no additional low-level implementation. In any case, contact the hardware's manufacturer and ask them about the methods suggested / provided for outputting audio/video stream. As for … | |
Re: Your problem is not related to the comp class or anything like that. You have a memory corruption problem. The problem is on the line 179 and 206: [CODE] for (int i=0; i < sizeof(rutor); i++){ [/CODE] The sizeof() operator returns the total size, in memory, of the variable or … | |
Re: As said, the new C++ standard solves your implementation problem with the new feature of variadic templates. However, there is also a solution that solves the problem you made your class for. The library called [URL="http://www.boost.org/doc/libs/1_47_0/libs/bind/bind.html"]Boost.Bind[/URL] (which is also now part of the new standard) was made for that purpose, … | |
Re: The standard class for this purpose is [URL="http://www.cplusplus.com/reference/std/limits/numeric_limits/"]std::numeric_limits[/URL], in the <limits> header. You can basically use it in this way: [CODE] template <typename T> T getMaximumValue() { if( std::numeric_limits<T>::has_infinity() ) return std::numeric_limits<T>::infinity(); else return std::numeric_limits<T>::max(); }; [/CODE] So, if you are using the "double" type for example, you could do: … | |
Re: >>I've heard that g++ emits more portable code but shouldn't they both be standard compliant? Standard compliant? That's an ideal, not a reality. The only compiler that exists which is fully compliant to the C++98 standard is the Comeau compiler (and it took significant efforts to make it compliant, which … | |
Re: >>If I am just "using" it then does it mean, my function names are still in global namespace Yes. The using statement simply makes it so that you don't have to qualify the namespace anymore when you _use_ things from that namespace. It doesn't mean that your code gets added … | |
![]() | Re: You cannot use an array that big. Your problem definition specified a limit of 1Mb, I guess it means you need to stick to that. You say that 6 digit numbers or less works fine in your range array. But more that 6 digit, i.e. 1 million, would cause the … ![]() |
Re: The answers so far are very good and pretty complete, but I'd add a few things: >>also can someone explain when i use unsigned variables?? Well, the only unsigned type you would really every use it [ICODE]unsigned int[/ICODE] (or a similar type like uint64 and such). Unless you need an … | |
Re: >> Now I need to register callback function so that when Model is done it will update view using that callback. You have stumbled upon the reason why I don't like MVC very much. The "idea" of MVC is that the Model should be only a slave to the other … | |
Re: [QUOTE]Now size of final will be: 4032. as Final will have common A through B and C. Here is the break down of the memory allocation: 4000 for int array. 4 for int c in C + 4 byte padding. 4 for int b in B + 4 byte padding. … | |
Re: Or [URL="http://qt.nokia.com/products/"]Qt[/URL], Or [URL="http://www.libsdl.org/"]SDL[/URL]. | |
Re: [QUOTE]P has a function setupBuffer() and is called by the constructor. I want the child class to overide it such that when the parent calls setupBuffer() it calls the child's version. Should either be virtual?[/QUOTE] No. You cannot achieve this, whether your function is virtual or not. You cannot safely … | |
Re: >>Union with a name seems a lot like a structure or a class, That's because a union is a heck of lot like a struct or class except that all members share the same address in memory and the union is as large as the largest (aligned) data member it … | |
Re: You can use the [URL="http://www.boost.org/doc/libs/1_47_0/doc/html/date_time.html"]Boost.Date-Time[/URL] library and the [URL="http://www.boost.org/doc/libs/1_47_0/doc/html/thread.html"]Boost.Thread[/URL] library, they offer timing functions with, in theory, a precision up to nano-seconds and similarly for the thread sleeping functions. Of course, when your system cannot support nanosecond timing then it will be rounded to the smallest possible precision your computer … | |
Re: Well, the new standard came out yesterday. It's not even published yet. Don't expect C++0x / C++11 books just yet. And be even more patient for compliant compilers. Right now, the best resources for C++11 are: [URL="http://en.wikipedia.org/wiki/C%2B%2B0x"]The C++0x wikipedia page[/URL]. Bjarne Stroustrup's [URL="http://www2.research.att.com/~bs/C++0xFAQ.html"]C++0x FAQ page[/URL]. The last published draft of … | |
Re: I can only give you an example in C++, because, to my knowledge, you cannot do compile-time polymorphism in Java. (and anyways, such a question belongs in the Java forum) This is dynamic polymorphism in C++: [CODE] #include <iostream> struct Animal { virtual void doCry() = 0; }; struct Dog … |
The End.