From: Terry G on 9 Oct 2006 23:11 Does Parent declaration have a terminating semicolon? class Parent { }; // <---- semicolon terry -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: lancediduck on 10 Oct 2006 08:17 Thomas Tutone wrote: > Sideswipe wrote: > > > I have the following > > > > #include "Parent.h" > > > > class ChildA : public Parent { > > > > SomeOtherClass klass; > > } > > > > and I get > > error C2504: 'Parent ' : base class undefined > > Please post Parent.h - the answer lies there. > > In the meantime, my crystal ball tells me the problem is probably one > of the following: > > 1. Improper use of #include guards in Parent.h. Check them carefully > - did you say "#ifdef" when you meant "#ifndef" ? > 2. Parent.h defines class Parent in a namespace. Or > 3. Parent.h does not define class Parent. > > Best regards, > > Tom This seems to be on track to discoveing the problem. Additionally, make sure that "Parent" isnt really a macro. Try #ifdef Parent #undef Parent #endif //"class Parent" still good, but "#define Parent" is killed off . A nice bug spray Believe me, I've seen worse when inheriting other people code. WE of course would never do something like #define new(X) malloc(sizeof(X)); which I have seen other ("well meaning," to put it politely) programmers do!!! So dont assume anything. Open up Parent.h and check that it is not a forward declaration, or make sure that the last '}' is actually there. Think in very literal terms -- what you are doing by #include is opening up Parent.h, and cutting and pasting it right where you include it. Does cutting and pasting it there make sense? And if that does not give you results, start considering the odd corners of the language, like digraphs. Indeed THIS code will give you problems depending on compiler settings bool a, b; //initialized elsewhere bool const not=a!=b; if(not) //do something //sometimes compiles sometimes not This one recently bit me, after 15 years of C++ programming,.... (Yep 'not' is a keyword in C++, but rare and mostly enabled on a few UNIX based compilers. Most PC compilers dont bother) -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Carlos Moreno on 10 Oct 2006 08:21 Sideswipe wrote: > and I get > error C2504: 'Parent ' : base class undefined > > It happens as soon as I include the SomeOtherClass declaration which is > #included in "Parent.h" the error occurs. > [...] > I assume somehow in my circular include it is forgetting to include > "Parent" > > this is driving me crazy -- help? Forward declaration, perhaps? If class A needs to know about class B and class B about class A (or some longer circle), then the chicken-or-the-egg breaker is that you forward declare, say, class B right before class A's declaration/definition: --- File A.h --- class B; // This is a forward declaration class A { A (const B &); // Compiler only needs to know that B is the // name of some class -- it does not need to // know th whole story about that class to // just deal with a reference to that class. }; --- End file A.h --- Then, when you *implement* class A's members, by then you'll have to provide the compiler with the entire class B's definition; but that's in the implementation file (.c++, .cpp, etc.), and that one is outside the loop of #included files, so no risk of trouble there: --- File A.c++ --- #include "B.h" A::A (const B & b) : d_a (b.whatever()) ... etc. { ... etc. } --- End file B.h --- (notice how inside file A.c++, the compiler must know the whole story about class B -- otherwise how would it know the meaning of b.whatever(), or that b.whatever() is legal/allowed?) HTH, Carlos -- -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: werasm on 10 Oct 2006 14:16 Sideswipe wrote: > and I get > error C2504: 'Parent ' : base class undefined > > It happens as soon as I include the SomeOtherClass declaration which is > #included in "Parent.h" the error occurs. Here is a similar problem that I recently had. Caused some templates not to see some definitions... Had me spinning for a while. Everything had unique (correct) include guards (not included for brevity), but one file had a cut and past error causing the wrong file to be included. If one draws it out you can easily see why. //--- test.cpp //Swap includes in test and all is well. #include "c_5.h" #include "c_1.h" //--- c_1.h #include "c_2.h" //--- c_2.h #include "c_3.h" //--- c_3.h #include "c_4.h" //--- c_4.h #include "c_5.h" //--- c_5.h #include "c_2.h" If I included "c_1.h" first, everything worked fine. If I did not, undefined (or unknown) types existed in "c_4.h". The reason for this was that c_5 included c_4, which in turn could not include c_5 as result of the include guard (c_4 was dependent on definitions in c_5 - typically it needed to inherit from a type defined in c_5). c_5 never really needed to include c_3 (and all its baggage:-) - this was a cut and paste error). Of course, there were many other files included that hid the big loop. And if ever c_1 happened to be included first, all worked well. This problem has similar symptoms, but then there could be many reasons. Regards, W -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Joshua Lehrer on 10 Oct 2006 14:37 lancediduck(a)nyc.rr.com wrote: > bool a, b; //initialized elsewhere > bool const not=a!=b; > if(not) > //do something > //sometimes compiles sometimes not > > This one recently bit me, after 15 years of C++ programming,.... (Yep > 'not' is a keyword in C++, but rare and mostly enabled on a few UNIX > based compilers. Most PC compilers dont bother) Any compiler which doesn't bother to implement 'not' is not standard conforming. 2.11.2 says: Furthermore, the alternative representations shown in Table 4 for certain operators and punctuators (2.5) are reserved and shall not be used otherwise: Table 4-alternative representations and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq _ 'not' is a reserved word. joshua lehrer http://www.lehrerfamily.com/ -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: fgets() vs std::getline() performance Next: error: invalid use of nonstatic data member |