I'm having an object declared in a class:
class B;
class A{
B object;
};
If I declare it B object; I get "object has incomplete type". If I declare it "B* object", the compilation ends successfully.
Why does that happens? I'm using C++11;
When declared as B object;
, A
needs the complete definition of B
so the compiler knows how large it is, and therefore how large A
is. When declared as a pointer, this information is not needed, because all pointers are the same size on a given platform.