From: Sideswipe on 9 Oct 2006 17:00 I have the following #include "Parent.h" class ChildA : public Parent { SomeOtherClass klass; } 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. Now, more information: SomeOtherClass.function() calls "new Child(this)" So obviously any Child must know about SomeOtherClass, and SomeOtherClass must know about Child. A circular include for which I have macro gaurds in place. Can someone explain to me how, when I declare the header right above the problem line, the compiler still doesn't know about my class? I assume somehow in my circular include it is forgetting to include "Parent" this is driving me crazy -- help? Christian -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Thomas Tutone on 9 Oct 2006 23:07 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 -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Alberto Ganesh Barbati on 9 Oct 2006 23:09 Sideswipe ha scritto: > SomeOtherClass.function() calls "new Child(this)" So obviously any > Child must know about SomeOtherClass, and SomeOtherClass must know > about Child. It's not so obvious from those information alone. From those information I deduce that SomeOtherClass need to know about Child, but Child does *not* need to know about SomeOtherClass. It just need to know about SomeOtherClass*, which is a completely different thing. A simple declaration of class SomeOtherClass will suffice, you don't need to include the whole header file. > about Child. A circular include for which I have macro gaurds in place. Apparently your guards aren't working as you expect. > Can someone explain to me how, when I declare the header right above > the problem line, the compiler still doesn't know about my class? Try looking at the preprocessor output. How do you obtain it depends on your platform; as you didn't know which one you're using I can't help you with that. Ganesh -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Jens Theisen on 9 Oct 2006 23:00 "Sideswipe" <christian.bongiorno(a)gmail.com> writes: > SomeOtherClass.function() calls "new Child(this)" So obviously any > Child must know about SomeOtherClass, and SomeOtherClass must know > about Child. A circular include for which I have macro gaurds in place. Guards will break the circle so that it's not circular anymore. Two headers that need to refer to each other's definitions is not going to work, if that's what you're trying to do. > Can someone explain to me how, when I declare the header right above > the problem line, the compiler still doesn't know about my class? If that's not what you're trying to do, maybe you just have two headers accidentely share the same guards; that's a common mistake. If this doesn't help you, you'll need to post a complete example. I can't really tell what you're problem is from what you've provided. -- Gruß, Jens -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Denise Kleingeist on 9 Oct 2006 23:10 Hello Christian! Sideswipe wrote: > SomeOtherClass.function() calls "new Child(this)" So obviously any > Child must know about SomeOtherClass, and SomeOtherClass must know > about Child. It sounds as if you try to define your member functions within the class definition instead of only declaring the necessary entities first and eventually when everythig is properly defined, not just declared, making use of the stuff. C++ is order dependent: it generally doesn't look at what else is coming later in the translation unit. The exception to this rule are member functions defined within the class definition: these look at all of the class, not just what was seen up to the point where the inline function is defined. A viable view is that such inline functions are treated as if they were written immediately after the class definition. > A circular include for which I have macro gaurds in place. The include guards are intended to avoid seeing the same definition twice. They don't help breaking circular dependencies. The tool to break circular dependencies at language level are forward declarations. At design level there is a huge host of additional tools to break circular dependencies. Good luck, Denise -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Next
|
Last
Pages: 1 2 3 Prev: fgets() vs std::getline() performance Next: error: invalid use of nonstatic data member |