If you need to, put class Widget; or whatever other class you have in front of everything so that you can use pointers to any class before the classes are actually defined.
ie:
Code:
class A;
class B {
A* func();
};
class A {
//...
};
If you want your member objects to contain a pointer to the object they are a member of, use a constructor. Pass 'this' to each object that way. ie:
Code:
class Widget { //...
private:
Widget(); //this makes sure that the only possible constructor is the bottom one
// You may want to declare a copy constructor to be safe
Container* parent;
public:
Widget(const Container* b) : parent(b) {}
};
class Container {
public:
Widget object;
C object2; //some other widget
Container() : object(this), object2(this) {}
}