2,898 Posted Topics

Member Avatar for Tinee

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 …

Member Avatar for mike_2000_17
0
134
Member Avatar for Labdabeta

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, …

Member Avatar for mike_2000_17
0
186
Member Avatar for jimmymack

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. …

Member Avatar for mike_2000_17
0
100
Member Avatar for Jsplinter

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 …

Member Avatar for mike_2000_17
0
2K
Member Avatar for miskeen

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 …

Member Avatar for vijayan121
0
227
Member Avatar for Jsplinter

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 …

Member Avatar for mike_2000_17
0
139
Member Avatar for n0de

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 ( ) ; …

Member Avatar for n0de
0
161
Member Avatar for NoUserNameHere

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. …

Member Avatar for NoUserNameHere
0
125
Member Avatar for lochnessmonster

>>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; …

Member Avatar for mike_2000_17
0
92
Member Avatar for aesthete

[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.

Member Avatar for mike_2000_17
0
50
Member Avatar for JohnBoyMan

>>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 …

Member Avatar for WaltP
0
86
Member Avatar for ztdep

-- 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 …

Member Avatar for mike_2000_17
0
177
Member Avatar for Loki55

[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 …

Member Avatar for mike_2000_17
0
114
Member Avatar for sahasrara

** 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(); …

Member Avatar for mike_2000_17
0
216
Member Avatar for Labdabeta

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 …

Member Avatar for nezachem
0
154
Member Avatar for Sahilroy

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 = …

Member Avatar for mike_2000_17
-3
153
Member Avatar for eman 22

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 …

Member Avatar for mike_2000_17
0
88
Member Avatar for shyla

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.

Member Avatar for Moschops
0
555
Member Avatar for predator78

>>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 …

Member Avatar for NicAx64
0
380
Member Avatar for sha11e

>>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 …

Member Avatar for sergent
0
213
Member Avatar for L0s3r

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. …

Member Avatar for L0s3r
0
190
Member Avatar for tikoti

>>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]

Member Avatar for tikoti
0
172
Member Avatar for pcgamer2008

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 …

Member Avatar for mike_2000_17
0
122
Member Avatar for cableguy31

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 …

Member Avatar for cableguy31
0
324
Member Avatar for merse

>>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 …

Member Avatar for Narue
0
163
Member Avatar for owenransen

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 …

Member Avatar for mike_2000_17
0
165
Member Avatar for dyingatmidnight

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. } …

Member Avatar for mike_2000_17
0
281
Member Avatar for Howdydoody
Member Avatar for eskimo456

>>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 …

Member Avatar for eskimo456
1
123
Member Avatar for daviddoria

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 …

Member Avatar for mrnutty
0
742
Member Avatar for thilinam

@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 …

Member Avatar for thilinam
0
1K
Member Avatar for lesfleurs

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 …

Member Avatar for mike_2000_17
0
202
Member Avatar for sha11e

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 …

Member Avatar for mike_2000_17
0
278
Member Avatar for frenzra

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 …

Member Avatar for mike_2000_17
0
99
Member Avatar for Khoanyneosr

>>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 …

Member Avatar for n.cramp
0
173
Member Avatar for The physicist

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 …

Member Avatar for The physicist
0
2K
Member Avatar for yapkm01

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.

Member Avatar for yapkm01
-1
321
Member Avatar for jnewing

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 /** * …

Member Avatar for mike_2000_17
0
95
Member Avatar for sing1006

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 …

Member Avatar for sing1006
-1
113
Member Avatar for sdr001
Member Avatar for sdr001
0
191
Member Avatar for atticusr5

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 …

Member Avatar for mike_2000_17
0
148
Member Avatar for lochnessmonster

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 …

Member Avatar for mike_2000_17
0
127
Member Avatar for jamesl22

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 …

Member Avatar for jamesl22
0
282
Member Avatar for newbiecoder

>>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 …

Member Avatar for awie10007
0
268
Member Avatar for kratosaurion

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 …

Member Avatar for kratosaurion
0
456
Member Avatar for bensewards

>>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 …

Member Avatar for bensewards
0
758
Member Avatar for fandango

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 …

Member Avatar for fandango
0
377
Member Avatar for daviddoria
Member Avatar for DestinyChanger

>>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 …

Member Avatar for DestinyChanger
0
212
Member Avatar for Ninjaboi

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 …

Member Avatar for Ninjaboi
0
2K

The End.