This is forward declaration. When using a class "ClassA" as a member in
another class "ClassB", you will define "ClassB" before "ClassA". But
if "ClassB" also have a member of "ClassA" you have a cycle. You can
solve this problem by using forward declaration.
No, a forward declaration does not solve the situation you
show below, which simply cannot be resolved. (Think about it
for a moment). A forward declaration only allows a pointer
or reference to the forward-declared class to be declared without
its full class definition visible.
class ClassA; // forward declaration
class ClassB {
public:
ClassA a;
/* ERROR */
};
class ClassA {
public:
ClassB b;
};
class ClassA;
class ClassB
{
ClassA a; /* ERROR */
ClassA& r; /* OK */
ClassA *p; /* OK */
};
class ClassA
{
};
class ClassC
{
ClassA a; /* OK, full def of ClassA visible */
};
-Mike