It is possible, but a bit more complex.
Firstly you should use pointers for classes like ContextGraphics.
So, the field will look like
ContextGraphics* graphics_context;
And it will work just with a forward declaration before windows class, like this
class ContextGraphics; // forward decl
class Window{
public:
...
};
Now, why is this is it necessary to use a pointer, and what the compiler really wants: When compiler see "ContextGraphics graphics_context;" it will try to 'inprint' the field into class Windows. To do it, compiler should know sizeof(ContextGraphics), which is only known when the class is fully defined.
That's why the following is impossible:
class Aaa;
class Bbb;
class Aaa
{
int x;
Bbb b;
};
class Bbb
{
Aaa a;
int y;
};
(Just think of it: suppose sizeof(Aaa) is 100, then sizeof(Bbb) is sizeof(Aaa)+4 is 104, but if so, sizeof(Aaa::a) is 104 too, and so sizeof(Aaa) is really 108 - this is where the circle really is.)
Now, using a pointer (ContextGraphics* graphics_context;) problem is solved, because compiler knows it's size, it's constant for any pointers.
So, the following will work:
class Aaa;
class Bbb;
class Aaa
{
int x;
Bbb* b;
};
class Bbb
{
Aaa* a;
int y;
};
(sizeof(Aaa) == 8 and sizeof(Bbb) == 8, for 32bit system)
In fact pimplIdiom itself requires most of inprinted fields to become pointers, because it's the only way for a compiler to know the fields size (or function params' sizes) without knowing the class itself.
And by the way (offtopic), you are building a library which already exists - called Qt, probably this will save you a lot of time. If it's about gamedev - Qt offers quite good perfomance also.