2,898 Posted Topics

Member Avatar for smcguffee

First [URL="http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.3"]read this[/URL], then [URL="http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.8"]this[/URL], and finally [URL="http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.5"]this[/URL]. I'm not sure I fully understand what you are trying to do (can you show some pseudo-code). If you are trying to simply re-use the code to do the initialization of the class, then, of course, a separate initialization method (function) would …

Member Avatar for smcguffee
0
117
Member Avatar for newbie_to_cpp

Change the type of display_Desig at a pointer to char, char *. And with the single equal sign for assignment, it should fix the compilation error. For the rest, there at least two small things to change / add: 1. change the type of all those B_SAL, H_ALLOW... variables to …

Member Avatar for newbie_to_cpp
0
2K
Member Avatar for mimis

In this case, the struct is, IMO, totally appropriate. And NO, [URL="http://www.parashift.com/c++-faq-lite/classes-and-objects.html#faq-7.9"]there is no functional difference between classes and structs[/URL] except for the default access rights (private, public) which you shouldn't use anyways because it is better to be explicit about the access rights. In this case, the data inside …

Member Avatar for mrnutty
0
164
Member Avatar for oscarp

Here are a few facts: 1. If you hold a map of objects (not pointers) of the base class, then it's going to be objects of the base class, not a derived class, that's impossible without a very nasty hack (reinterpret cast on the object). DON'T DO THAT! 2. There …

Member Avatar for mike_2000_17
0
2K
Member Avatar for aikiart7

Ok, so the statement you are having an issue with is: [CODE]if(!head)[/CODE] Lets go by it step by step. First, the if-statement, of course, takes a boolean value (true or false) and executes the next statement if that boolean value is true. Then, the ! operator is the NOT boolean …

Member Avatar for aikiart7
0
108
Member Avatar for Nathaniel10

>>I am using the modulo operator with a double when it can only be used with ints. Although you don't need it here, if you do need in the future, the modulo function for double is [URL="http://www.cplusplus.com/reference/clibrary/cmath/fmod/"]fmod()[/URL].

Member Avatar for Nathaniel10
2
141
Member Avatar for ChaseRLewis

Simply make a MACRO to wrap the function call: [CODE] //in MyDebugUtilityFunctions.h void ReportError(int lineNumber,Wstring ErrorTitle,Wstring ErrorMessage) { ... report the error ... }; #define MY_DEBUG_ERROR_REPORT(X,Y) ReportError(__LINE__,X,Y) //say in the main.cpp, or anywhere else. int main() { ... MY_DEBUG_ERROR_REPORT("Fatal Error!","The main function crashed here!"); ... }; [/CODE] The MACRO will …

Member Avatar for ChaseRLewis
0
127
Member Avatar for yosi_s85

Every floating-point representation like float, double, or even long double, will inherently have a round-off error. Usually, for these three types it is rounded-off around the 7, 16, and 20 significant digit (although long double may not be different from double, and the precisions can change per platform). So, even …

Member Avatar for mike_2000_17
0
204
Member Avatar for onako

I would recommend you switch to cmake instead, but to fix your makefile. Add the "$(pkg-config --cflags --libs cairo)" to CPPFLAGS, like this: [CODE] CPPFLAGS += $(pkg-config --cflags --libs cairo) [/CODE] I'm pretty sure that or a variation of it should do the job, but I'm not an expert on …

Member Avatar for Stefano Mtangoo
0
141
Member Avatar for smcguffee

@Fbody: you covered two good cases, but none are about the OP's question. If you have a nested class, then the this pointer, within a call to a member of the nested class, refers to an instance of the nested class (not its wrapper class). However, the nested class has …

Member Avatar for smcguffee
0
121
Member Avatar for Gait

Just throwing in my grain of salt.... I'm mainly a Linux user so I may be biased. I find mingw (as I assume it is the same as the Linux gcc) to be much more helpful in general. It is easier to know that your are compiling and the error …

Member Avatar for hystaspes
0
147
Member Avatar for smcguffee

Well you are stepping into the realm of const-correctness which is this idea that if you want to be rigorous, you should put const everywhere where a variable is constant or required to be constant. You are right that a lot of people (especially beginners) are frustrated at the const …

Member Avatar for smcguffee
0
126
Member Avatar for spankboy11

Don't use the code from sundip, it is erroneous. In your original code, there is a memory leak because you loop again and reallocate the memory for a new array on top of the previous one. Since the destructor of all those Fuzzy objects don't get called, the n value …

Member Avatar for Kanoisa
0
246
Member Avatar for tennis

>>what is the int in operator++(int) It's just used to differentiate the two functions. It means nothing at all.

Member Avatar for webweb2
0
78
Member Avatar for michdd

[URL="http://www.parashift.com/c++-faq-lite/pointers-to-members.html"]This page[/URL] might help, but I'm sure it's the first you found in researching this issue. I know why the error happens. "this" and "this" are different. Let me explain. The this pointer you pass to the function is of type TitleScreen* but can be implicitly casted up to a …

Member Avatar for mike_2000_17
0
150
Member Avatar for ftl25

I see one big problem. You should not do anything complicated in the DLL entry point function. This is because there are certain intrinsic properties that make the DLL_entry somewhat different from a normal function call. These special things have to do with the OS being able to load the …

Member Avatar for mike_2000_17
0
122
Member Avatar for daviddoria

I think, you have to make the pointer a private or protected member, because the compiler will say it is incomplete because it should be accessible to an outside part (like main()) which has no idea what the real declaration of myVector is. Since the VecPtr can be dereferenced in …

Member Avatar for daviddoria
0
263
Member Avatar for indigo.8

The code you posted is a bit weird, what is C1dArray? Anyhow, simply put: [CODE] ... imgArray = new unsigned char *[size]; myStream.read(reinterpret_cast<char *> (imgArray),(fileSize)*sizeof(unsigned char)); //notice fileSize not size //set the nullterminating char, if you really need it (IMO you don't). imgArray[size-1] = 0; int* pArray = new int …

Member Avatar for indigo.8
0
5K
Member Avatar for Duki

There is no implementation for either of these methods: [CODE] void Mob::set_data(string name, int level, int given_xp, int given_gold, int attack, int defence, int max_hp, int max_mp, int max_tp, int attack_spd); void Mob::add_ability(Ability); [/CODE]

Member Avatar for Duki
0
99
Member Avatar for NordCoder

You have to specify the correct include path in your own stuff too. This error is not in the FTGL library which compiled successfully. Once compiled, it no longer needs to find the includes for the .lib, but it needs to find the includes that you use in your code …

Member Avatar for NordCoder
0
614
Member Avatar for prit05

C: forget it, it is possible of course, but I can comfortably say that people don't really make a conscious choice to program in C. Usually it is because either it is a special very low-level platform for which C is the only choice, or because its an old library …

Member Avatar for Duki
0
179
Member Avatar for michdd

I know you solved the problem, but may I suggest a more elegant method IMO. This is a typical case where an interface class and multiple inheritance could do very well: [CODE] //Callback.h class IMouseClickCallback { public: virtual void MouseClickCallback() = 0; }; //Client.h class Client : public some_other_base_if_any, public …

Member Avatar for mike_2000_17
0
189
Member Avatar for mommabear

>>I'd also recommend putting all includes into the header file rather then the .cpp NO absolutely not, if we are talking about best practices in coding. OP: The way you did it is fine. You include as few headers as you can in your headers and include the headers you …

Member Avatar for mike_2000_17
0
351
Member Avatar for frogboy77

Well, as a start, you need to split the number into each base 10 digit, for example: [CODE] std::vector<int> SplitDigits(int Number) { std::vector<int> result; while(Number > 0) { result.push_back(Number % 10); Number /= 10; }; return result; }; [/CODE] That's a start, now you go from there and figure out …

Member Avatar for frogboy77
0
84
Member Avatar for ftl25

The problem is that pTSL1_Commands->TSL1_ReadMemory32 is a "method" not a "function". The difference is that a method has the implicit "this" pointer to the object passed to it, while a function only has the parameters of its prototype declaration. So a function pointer, if you need to use one and …

Member Avatar for ftl25
0
186
Member Avatar for DBlue

Well, there are several places to put it, depending on what you want. I am not an expert with VC++, so the names I give my not apply directly (they would apply directly to Borland C++Builder and VCL) but usually they correspond well. Usually there are callback functions, like OnClick() …

Member Avatar for mike_2000_17
0
122
Member Avatar for pdk123

I don't mean to interrupt, but usually when you want a really robust binary interface for a byte-stream. You don't cast, or stringify, or pack/pragma, or what give you. You implement a binbag with off-the-hook protection from cross-platform, cross-compiler, cross-compiling-option.. the whole shabang. Implement the binbag's interface on the model …

Member Avatar for mike_2000_17
0
162
Member Avatar for sana_moi

Ton problème est que lorsque tu fais l'addition de plusieurs chaines de charactères, ses chaines sont converties en "String^" pour être additionner. Une fois additionné, tu as un String et non une chaines de charactère (char[] ou char*), et ils ne sont pas compatible implicitement. Donc, pour régler le problème, …

Member Avatar for sana_moi
0
172
Member Avatar for AdventGamer

Did you consider making a method instead? such as: [CODE] template <typename T> class node { public: T nodeValue; //data held by the node node<T> *next; //next node in the list //default contructor with no initial value node() : next(NULL) {} //constructor. initialize nodeValue and next node(const T& item, node<T> …

Member Avatar for mrnutty
0
1K
Member Avatar for TheWolverine

The problem is that you need to have the same access right for the overwritten function in the derived class, otherwise, the compiler will call the public function first. So, simple correction: [CODE] class BaseClass { public: void setInputParameter() { inputParameter_ = inputParameter; } void computeFunction( const double& inputParameter ) …

Member Avatar for mrnutty
0
2K
Member Avatar for shahanakazi

We don't just solve assigments here! You start it, get some code going, and post specific problems with the code you have. We have to see that you have been making a real effort to solve this problem by yourself. We only give help to cross the few hurdles you …

Member Avatar for shahanakazi
0
93
Member Avatar for indr

that simple: floating point values on a computer always approximate the real value to some round-off error (about to the 7th significant digit for float and to the 20th significant digit for double). So the comparison i<=stop_temp is not going to work all the time because even when i is …

Member Avatar for Luther von Wulf
0
119
Member Avatar for romilnagrani

NO, if only the return type differs, they cannot be overloaded (i.e. have the same name). C++ standard specifies that overloading is only for different parameters (their types or their number), not return types. So, to have different return types. You have a few options (in order of what's easier …

Member Avatar for mike_2000_17
0
136
Member Avatar for Dazaa

>>does that mean that I need to overload the operator to work with my class? NO absolutely not. DO NOT OVERLOAD THE -> OPERATOR! The correct syntax in your case is: points[size].x

Member Avatar for mike_2000_17
0
144
Member Avatar for dflatt

You had some things the wrong way around: [CODE] subarray(int* Array, int start,int end) { typedef int* ptr; ptr sub; int count = end - start; //the sub-array's size is not "end", but "end - start". if (count <= 0) //check that you actually have a sub-array to create. return; …

Member Avatar for dflatt
0
90
Member Avatar for gretty

Dumping a thread like this is not nice, but while we are at it. For outputting, I like this better: [CODE] //in some basic header of your software. #ifndef DEBUG_VERBOSITY #define DEBUG_VERBOSITY 5 #endif #define DEBUG_NOTICE(X,Y) if(X <= DEBUG_VERBOSITY) std::cout << __FILE__ << ":" << __LINE__ << " " << …

Member Avatar for Dingbats
0
157
Member Avatar for miturian

From my experience, this looks like a memory corruption problem. Maybe playing with valgrind can help you. Also, try outputting the pointer addresses you use. verify each dynamic memory allocation to make sure you never use an uninitialized pointer. Also check bounds on for-loops and stuff, make sure you are …

Member Avatar for miturian
0
151
Member Avatar for yup790

@yup790: Try this code, and you can hand it in as is: [CODE] #include <iostream> #include <algorithm> #include <functional> using namespace std; const char hello_world[] = {0x49,0x20,0x61,0x6D,0x20,0x61,0x20,0x63,0x68,0x65,0x61,0x74,0x65,0x72,0x21,0x00}; struct printOutFunctionObject { void operator () (int) { cout << hello_world << endl; }; }; struct null_iterator { bool operator !=(const null_iterator& iter) …

Member Avatar for mrnutty
0
221
Member Avatar for vbx_wx

[URL="http://stackoverflow.com/questions/137038/how-do-you-get-assembler-output-from-c-c-source-in-gcc"]Read this[/URL].

Member Avatar for mike_2000_17
0
43
Member Avatar for mrkaran

MACROs are evil! Don't use them. From the looks of it, that you need is a look-up table. If you are restricted to C, from the looks of your code that is the case, then you can do this: [CODE] struct myKeyword { const char name[]; int ID; }; myKeyword …

Member Avatar for mrkaran
0
88
Member Avatar for sfuo

What about this: [CODE] class vec3f { private: GLfloat q[3]; public: GLfloat& x() { return q[0]; }; GLfloat& y() { return q[1]; }; GLfloat& z() { return q[2]; }; vec3f(){}; vec3f( GLfloat x, GLfloat y, GLfloat z ) { q[0] = x; q[1] = y; q[2] = z; } *operator …

Member Avatar for mike_2000_17
0
157
Member Avatar for prince26121991

What Lusiphur said is true for freeing or deallocating memory. Most of the time, for small applications that don't run for very long and don't use any OS resources (like threads, external processes, internet connection sockets, etc.) it will work fine without explicitly freeing all allocated memory, but not good …

Member Avatar for Lusiphur
0
3K
Member Avatar for Rez11

Agreed. It is also good practice to play around with the example codes. For example if you are not sure why a particular line code is there or why the author does something in a particular way, you can just change it and see what happens. It's good to also …

Member Avatar for denguru4
0
117
Member Avatar for Silvershaft

Well in the above, the "&function" syntax is a function pointer which you can Google for. And the "hooks" that you are talking about is, from what I understand of your explanation, what is commonly known as "callback functions" which is very heavily used, especially in C interfaced libraries (such …

Member Avatar for mike_2000_17
0
96
Member Avatar for plizz

I see two things that could be happening that makes it compile without error in VC++: 1. VC++ might actually mangle the names differently according to return type, the standard allows it even though it really serves no purpose because overloaded return type are not supported, so who knows, maybe …

Member Avatar for mike_2000_17
0
277
Member Avatar for lilfish08

Well, since your original code is so far off, and sfuo already posted a valid solution, let me just post a slightly better one that applies if you don't care about the print order at all: [CODE] void printAllFactors( int in ) { //start at 2 if you want it …

Member Avatar for lilfish08
0
209
Member Avatar for lilfish08

You might have a dangling newline on the cin, so when you try getline it returns an empty line before you even have time to enter anything. Simple solution, replace the "cin >> answer;" part with: [CODE] cin.ignore(); //this will ignore any newlines that are on the input buffer but …

Member Avatar for lilfish08
0
173
Member Avatar for imthiyas92

[QUOTE]B=N*I*R*R/2[R*R+x+x]^3/2;[/QUOTE] Is not a valid C/C++ syntax. the ^ operator is not for power (it's binary XOR which I doubt is what you intended). C/C++ is not matlab or mathematica or a hand calculator. If the function is, as I understand it: B = (N * I * R * …

Member Avatar for mike_2000_17
-1
874
Member Avatar for xavier666

I think there is no need to dig up a place in the C++ standard where it says something like: "a class Foo derived from class Bar cannot access the protected members of Bar from another object of type Bar or any other of its derived class, including Foo." Because …

Member Avatar for Fbody
0
115
Member Avatar for Fbody

Well MSDN says this: [QUOTE]The classes in <strstream> are deprecated. Consider using the classes in <sstream> instead.[/QUOTE] And [url]www.cplusplus.com[/url] has no mention of strstream at all, it seems to have vanished from their standard library reference documents. It appears also that strstream uses char arrays in the underlying implementation while …

Member Avatar for Fbody
-1
159

The End.