-2

In class A contains a class B object

ClassB;
class A
{
    private:
    ClassB b;
}

sometimes declare classB is enough, sometimes,I have to use #include "ClassB.h", why? Any difference when using those two?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Adam Lee
  • 24,710
  • 51
  • 156
  • 236

1 Answers1

0

When forward declaring a class you can only use the forward declared class as a reference or pointer because at this point, the compiler is not aware of the size of this type. Here's a good stackoverflow post about what you can and cannot do with forward declarations.

Community
  • 1
  • 1
Tejas Sharma
  • 3,420
  • 22
  • 35