0

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;

yonutix
  • 1,964
  • 1
  • 22
  • 51

1 Answers1

3

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.

TartanLlama
  • 63,752
  • 13
  • 157
  • 193