c++ - forward declaration generates incompatible type error -
c++ - forward declaration generates incompatible type error -
i've been reading on forwards declarations, including in forum. saves including header file, next code generates error:
#ifndef classa_h_ #define classa_h_ class b; class { public: a(); ~a(); int getcount(); private: static int _count; int _num; b _b1; //error }; compiler says: a.h:23: error: field ‘_b1’ has incomplete type
i noticed if create _b1 of type b* problem solved.
so forwards declaration pointer types? if want a hold b object have #inlcude "b.h" ?
thanks!
the compiler has know exact definition of class b determine @ to the lowest degree size give class a. if utilize pointer, knows size.
note circular dependencies not possible. if want
class { b b; }; class b { a; }; then , b must have infinite size...
c++
Comments
Post a Comment