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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -