   question about inheritance in c++
  Lets say we have 3 classes:[a.h]include b.h;class a{  array of ptr* c;}[b.h]include a.h;class b{  ptr* a;}[c.h]include a.h;include b.h;class c : b{}this gives me"error C2504: 'b' : base class undefined"in VS C++.netI read about circluar includes,and i tried inserting class a; class b;in c.h, and other combinations...nothing works...so my question: "is this kind of relationship possible?"Thank You in advance   
[a.h]class c;class a{   c *array;};[b.h]// unless you *really need to, dont include a.h here// really need to means that you use class a inside the header file// you can include it in the source file instead if you have no inlined methods// that make use of aclass a;class b{   a *aPtr;};[c.h]#include "b.h"class c : public b{};;  so combine b.h and c.h?b.h is base class for all my GUI classesand a.h is my panel class that has pointersto all his GUI-elements-children.class c inherits from b.class b has a parent pointer which points to class a...And Thank You for a such a quick response   ;Quote:Original post by thecommiso combine b.h and c.h?b.h is base class for all my GUI classesand a.h is my panel class that has pointersto all his GUI-elements-children.class c inherits from b.class b has a parent pointer which points to class a...And Thank You for a such a quick responseNo, you do not need to combine them. Im not sure where you got that impression [smile]Perhaps its where I say "class X;". This is a forward declaration of class X, class X is an incomplete class. When you say that its telling the compiler "there is a class called X, you can pass it around but you cannot access any of its member functions or variables just yet". A pointer to a class is always the same size, regardless of the size of the "pointed to" class. So the compiler can always use a pointer to an incomplete class as a member variable.You cannot derive from an incomplete class though, the compiler must know the exact size of the parent class, which it cannot guage from class forward declaration.If you have pointers to X in another class Y, then in y.cpp you can #include "x.h" and make full use of the class. 2 classes can refere to each other in this way:// [one.h]class Two; // forward declare class Twoclass One{    Two *two;    int i;    void foo();};// [two.h]class One;class Two{    One *one;    int j;    void bar();};// [one.cpp]#include "two.h"void One::foo(){   two = new Two();   two->j++;}// [two.cpp]#include "one.h"void Two::bar(){   one = new One();   one->foo();}Note: although you can do this, you wouldnt want to have too much circular dependacy, its quite confusing. It can lead to strange method calll loops and stuff, try to avoid it as much as possible.The code I posted should* work as is.*although I havent tried it in a compiler, Im too lazy right now   ;  IIRC Organizing Code Files in C and C++ explained it pretty well.   ;  Thank You guys!so in practice circular relationships might causebad stuff later on?   ;  ok now that i am done with finals, i actually tried that stuff,maybe i am just not that smart but it doesn't work.I am still getting errors on my base class//panel.h#include "box.h"class box;class panel{    vector<box*> boxes;}// baseGUI.h#include "panel.h"class panel;class baseGUI{    panel* parent;}// box.h#include "baseGUI.h"class box : public baseGUI{}is there some other way to keep track of a parent?   ;  You need to remove #include "Box.h" from panel.h and remove #include "panel.h" from baseGUI.h  Like rip-off mentioned, move the includes to the .cpp file instead.   ;  this will give you errors in .h files, sincepointer to parent are defined in baseGUI.h andpointer to instance in panel.h...I dont think it is possible without making codereally messy.would this be better if panel inherits from baseGUIas well, and parent is a pointer to base class,and lets say base class has a function thatreturns a string that tells you what it really is?// baseGUI.hclass baseGUI{    public:  char* getID();  char* getParent()    private:  char* ID;  baseGUI* parent;}// panel.h#include "baseGUI.h"class panel : baseGUI{  char* ID = "panel";  vector<box*> boxes;}// box.h#include "baseGUI.h"class box : baseGUI{ char* ID = "box";}so when client accessing the parent, it will have to getbaseGUI first, then cast it to panel, or whatever type it really is.Would that be bad?   ;// panel.hclass box; // forward declaration, sufficient to declare pointers to boxclass panel{    vector<box*> boxes;}// panel.cpp#include "panel.h"#include "box.h"// remainder of source file// baseGUI.hclass panel; // forward declaration, sufficient to declare pointers to panelclass baseGUI{    panel* parent;}// baseGUI.cpp#include "baseGUI.h"#include "panel.h"// remainder of source file// box.h#include "baseGUI.h"class box : public baseGUI{}Σnigma   