Related to a previous question, I have now the following one:
In the next scenery:
class B;
class A
{
// stuff, methods and so on
B b;
};
class B
{
// stuff, methods and so on
A a;
};
Here we have a circular dependence between A
and B
, but this code is ill-formed since B
is an incomplete type. A solution is to change B
by a pointer of B
by means of a smart pointers for example. But adding pointer add complexity and resources spending unnecesarily since you don't need a pointer!
In the previous question I tried to avoid the use of pointers by means of templates, so I delay the instantation of the class at a point where both classes are defined, but I was incapable of doing it successfuly.
Is it impposible to avoid pointers? Are there well-known dessigns to avoid circular dependences?