2,898 Posted Topics
Re: After inputting a single character or a number, you should always make a call to [ICODE]cin.ignore();[/ICODE]. For the error, I can't be sure. Try to avoid using C-style strings, they can yield surprising errors. I suggest you use a stringstream based conversion from both appearances of itoa(). As follows, for … | |
Re: I don't know much about that. But gstreamer is the classic tool for video loading / decoding / displaying. Look at the list of [URL="http://gstreamer.freedesktop.org/documentation/plugins.html"]plugins[/URL], they have several "videosink" (which is the lingo for "displaying the video"), I believe it can be easily be used with OpenGL, SDL, X, Xv, … | |
Re: First of all, any good C++ book should tell you that the destructor in a base class has to be marked 'virtual' (unless you are an expert and intentionally leave it non-virtual in the context of some advanced programming technique, like scope-guards). Anyways, on my computer, it does as expected. … | |
Re: First of all, operators like comparison operators should usually be implemented as friend functions, not as member functions. In this case, that is not the problem. The problem is that your member functions for operators < and == both take a const reference (which is correct), but the member functions … | |
Re: First: seed you random number generator once with [ICODE]srand(time(NULL))[/ICODE]. Then, get a value between 0 and 31 using the modulus operator on the result of rand(), as so [ICODE]rand() % 32[/ICODE]. That gives you "n". Finally, use the bitshift operator to raise to the power of "n". As so [ICODE]1 … | |
Re: No. The methods are associated with the type of the object (i.e. the class), they are not associate with the object, so they require no extra storage space on a per object basis. In fact, you can easily test it, just apply the sizeof() operator on a class with and … | |
Re: If you want your addition operator to take a pentathlete_team, it should take a pentathlete_team and return one too. As so: [CODE] pentathlete_team operator + ( const pentathlete_team& sec_comp ) const { if ( sum_res < 0 ) { results ( ) ; } sec_comp . results ( ) ; … | |
Re: Most operators (except for the assignment, compound operator-assignment, and the few special operators like & and ->) can be implemented as a free function, not a member function of the class. Operator overloading should be regarded exactly as any other kind of function, they just have a different calling syntax. … | |
Re: >>Local * pLocal = *(Local**)0xE6EB54; // valid English translation: Take the literal numeric value of the hexadecimal number E6EB54 and interpret that numeric value as the address of an address to an object of type Local. Dereference this numeric value to obtain value stored at the address it points to; … | |
Re: [URL="http://freeimage.sourceforge.net/"]FreeImage[/URL] is a simple open-source library which can do this, no problem. If you have used any other external library in the past, it will be a walk-in-the-park to use this one. | |
Re: >>I have been programming for a while now Taking you on your word, I would assume that the explanations of the previous posters isn't what you were looking for, because if you have been "programming for a while" you definitely knew this already. Right? I'm sure your question is not … | |
Re: -- Here is a description of what you should NOT do -- You could do what firstPerson suggests, but that would just create an error at line 41 saying that you cannot convert a const T& to a T& (usually, the message for that is: "error: converting parameter of type … | |
Re: [CODE] if(number == 7) continue; [/CODE] This will skip the rest of the loop if the number is 7, and it will go back to the start of the loop (i.e. it will increment i, and check the end-condition). [CODE] if(number == 7) break; [/CODE] This will terminate the loop … | |
Re: ** Don't bump old threads like that, especially if you add nothing to it ** BTW, the C++ version of this code is this: [CODE] #include <iostream> #include <list> #include <algorithm> int main() { using namespace std; int number; list<int> lst; while((cin >> number) && (number != 0)) lst.push_back(number); lst.sort(); … | |
Re: First of all, assuming your binary string is stored from most significant bit to least significant bit, you will have to traverse it in reverse (from the end to the start), which isn't a big deal. The same goes for the output string. You will have to preallocate enough storage … | |
Re: Line 48 of function_definition.cpp: When you allocate new storage for a C-style string (char*), you need to add the null-termination character. This means you need to allocate one more char than what is given by [ICODE]strlen(tName)[/ICODE]. The same goes for line 663 (in function SaveToFile). As so: [CODE] Ptr->Name = … | |
Re: C++98 Standard Section 4.2 "Array-to-pointer conversion", paragraph 1: [QUOTE]An lvalue or rvalue of type “array of N T” or “array of unknown bound of T” can be converted to an rvalue of type “pointer to T.” The result is a pointer to the first element of the array. [/QUOTE] As … | |
Re: In your header, you need to match the [ICODE]#ifndef linkedlist_H[/ICODE] with a [ICODE]#endif[/ICODE] at the very end of the header file. In your cpp file, if you want to use the type listNode, you have to fully specify it, i.e. [ICODE]linkedList::listNode[/ICODE], otherwise the compiler won't find it. | |
Re: >>1. Are data structures essentially classes minus methods which can preform actions on the members that are held inside? What you are describing are "C-style structs" or, more commonly, "POD-types" (Plain Old Data types). These are not what people would call data structures (or at least, they are an extremely … | |
Re: >>Heard people say c# for big programs, May I suggest that maybe those people only programmed very small textbook-example-style programs in C++, and then made from "big programs" in C# and found it pretty easy to do. They probably also say "big programs" to mean GUI programs. C# is a … | |
Re: There is a special allowance for compilers to optimize away the copy constructor when returning an object by value from a function. Basically, the compiler sees that the returned object is assigned to a variable and thus will use that variable directly, within the function, to create the returned object. … | |
Re: >>I am looking for something to compact the clear and push_back in one line.. I don't see any point in doing this, but what about: [CODE] v.clear(); v.push_back(4); [/CODE] or, if you really want it to be one expression: [CODE] std::vector<int>(1,4).swap(v); [/CODE] | |
Re: The OpenGL window always goes from -1 to 1 on both x and y coordinates. You can just take those windows coordinates in pixels and use some simple formulas to transform the ranges [0, pixel_width] and [0, pixel_height] into [-1,1] and [-1,1], and that's it. If you want to actually … | |
Re: There is a ton of randomness on the internet. You could ping some known website(s) and record to RTT with micro-second precision (which is what most ping programs will give you). That should be random enough for any purpose. Similarly, you can initiate a TCP dump and record the IP … | |
Re: >>I expect that the * operator doesnt try to calculate log() if w=0, C++ cannot make those kinds for simplifications, because operators can be overloaded and thus, it cannot really know that a variable is 0, nor can it assume that 0 * anything = 0, because it might not … | |
Re: Ok, so, you mean what is the difference between: [CODE] for(GlifPtrVec_t::iterator it = m_Array.begin(); it != m_Array.end(); ++it) delete *it; [/CODE] And: [CODE] for(int i = 0; i < m_Array.size(); ++i) delete m_Array[i]; [/CODE] You should think of iterators as pointers, that is what they are meant to mimic in … | |
Re: I don't understand how your code does compile, it shouldn't. Here are some comments and errors: [CODE] class Telegraph{ public: Telegraph(){ int const size = 32; //make this value a static const data member. int *telegraph = new int[size]; //telegraph is a static array, this should not be allowed. } … | |
Re: You forgot the [ICODE]DirectGraph::[/ICODE]. | |
Re: >>is there any advantage/disadvantage to doing everything as a template? Advantages: - You get truly generic, expendable implementations. - You suffer no run-time overhead (and often a speed-up). - Policy, Traits, and Concepts are much more flexible than base classes or interfaces in OOP. - Inversion of Control (IoC) can … | |
Re: Well, first of all, lets get rid of the obvious solutions (that you have ruled out): 1) You can use a symbolic math library. Like [URL="http://en.wikipedia.org/wiki/GiNaC"]GiNaC[/URL]. Enter the formula as a string expressions, substitute the known variables and ask it to solve for the value of the unknown(s). But the … | |
Re: @AD>>..C++ programs are pretty much operating system specific. What on Earth are you talking about? There are robust cross-platform libraries for everything in C++ (you just have to stay clear of anything that bares the name Microsoft or Apple). The amount of platforms you can target with platform-independent code in … | |
Re: I would imagine (since there is not enough code to tell), that the error is due to "originalTree" not being NULL, yet being invalid (either a pointer that has been deleted or a garbage address (uninitialized value)). Make sure that there is no way that either root, left or right … | |
Re: How you would need to do it is as follows (explanation will follow): [CODE] //header.h #ifndef HEADER_H #define HEADER_H void test(); #endif [/CODE] [CODE] //main.cpp #include <iostream> #include "header.h" //to find the test() function. int main() { test(); return 0; } [/CODE] [CODE] //declerations.cpp #include "header.h" #include <iostream> //for using … | |
Re: The library to use is <fstream> for file I/O. You can do simple input of a number or line (string) as follows: [CODE] #include <fstream> #include <string> int main() { std::ifstream in_file("my_list.txt"); //opens the file "my_list.txt" int code; //declare variable for the integer code std::string name; //declare a variable for … | |
Re: >>are there any real techniques for drawing shapes? Of course there are. But what "shapes" are you talking about? When it comes to shapes made of polygons, we usually talk about a mesh. Typically people use 3D design programs (like 3D studio max, or Blender3D, or Milkshape), and create 3D … | |
Re: Are you sure that calling path.append("file1") does not change the string stored in "path"? I would bet that is the problem, in fact, I know. Try using this instead: [CODE] // switch statement to changed filename switch(j){ case 1: fileName = path + "file1"; break; case 2: fileName = path … | |
Re: For the answer to your question, please refer to section 8.5 and 12.1/5-6-7-8 of the C++ standard (1998). And, yes, it is irritating when posting on several forums. Different forums have different feels to them, and some do indeed participate in many. | |
Re: You just need to enclose everything in the namespace. As so: [CODE] /** * lib1.h */ #ifndef LIB1_H #define LIB1_H #include <iostream> #include <fstream> #include <vector> namespace MyLib { class Lib1 { public: Lib1(); ~Lib1(); int some_lib1_function(int foo); private: Lib1 *lib1; }; }; //end of namespace MyLib #endif /** * … | |
Re: Your terminology is wrong, that is why your internet searches on the subject fails to yield anything. The correct term is "passed-by-value" and "passed-by-reference", i.e. "passed" not "call". Call-by-value makes no sense (those who use this terminology do so incorrectly). In lay terms (similar to GaidinDaishan): Imagine you are one … | |
Re: You have to post more code. And also the compilation error you get. | |
Re: The error is in lines 144 and 155. In the first case, you are accessing the Left node, but the checked condition involved a logical OR expression, which means if Right node is valid (not NIL) then you proceed to access the Left node which may or may not be … | |
Re: Narue is right. I would classify the ID data under "implementation details", i.e., stuff that should be encapsulated and hidden from the user (maybe accessible through a get function). I probably would go as far as not even providing a constructor that takes an ID, just ones that take high-level … | |
Re: If you are writing an FPS game, you are going to need some way of executing animations (i.e. things that move as a function of real-time), like for bullets, clouds, non-static objects, etc.. Once you integrate a means to do that, it shouldn't be a problem to implement a smooth … | |
Re: >>Can you give me a few tips about that? code, code, then code some more. Do it until your fingers or brains are numb (whichever occurs first), then rest, then repeat. Find a project you like, and get cracking. Make sure the project is within your grasp, but does challenge … | |
Re: Several observations: 1) remove the semi-colons after the include statements. 2) #include <cstdio> instead of <stdio.h> (in fact, I don't think you need it at all) 3) If you just removed the "feature" of outputting text in different colors, this program could run on Linux just as easily (removing the … | |
Re: >>how do you feel about letting a 15 year old do your homework (if it is homework) I guess the OP should feel some shame in that. But, you should too (a bit). It is generally not helpful to the OP to simply post finished work. @OP: You should not … | |
Re: I don't think this will always work. If you look at the synopsis of [URL="http://www.cplusplus.com/reference/algorithm/min_element/"]min_element[/URL], you will see that it starts by using the first element as the lowest one. If the first element has really small distance but does not satisfy the predicate, you will be in trouble. You … | |
Re: >>don't want to use boost or AfxBeginThread(). Good luck. So, I'm guessing that if you don't want to use AfxBeginThread() which is just a thin wrapper around [URL="http://msdn.microsoft.com/en-us/library/ms682453%28VS.85%29.aspx"]CreateThread[/URL], then you don't want to use CreateThread either. And if you don't want to use Boost.Thread, then you probably won't want to … | |
Re: Another simple solution to not cluttering your main install directory, and I believe this solution is pretty frequent, is to put your "real" executables and DLLs in a subfolder (like "bin") and then write a simple "launcher" executable to put in the main install directory, that launcher just starts the … |
The End.