c++ - Why doesn't foward declaration of class work when class is included in another class -
this compiles
#include "sprite.h" class gameobject { public: int x, y, w, h; sprite sprite; public: gameobject(); gameobject(int _x, int _y, int _w, int _h); virtual ~gameobject(); };
this doesn't
class sprite; class gameobject { public: int x, y, w, h; sprite sprite; public: gameobject(); gameobject(int _x, int _y, int _w, int _h); virtual ~gameobject(); };
i know forward declare , use pointer sprite why doesn't forward declaration works here. doesn't "class sprite;" tells sprite exists? i'm trying #include classes in .cpp , avoid in .h @ cost. classes not including each other there no need use sprite*. guess understanding of forward declaring is wrong or because don't see reason why doesn't work.
thanks in advance.
pretend you're compiler. without having complete declaration of sprite
@ disposal, how possible determine whether sprite
1 byte big, or 1 hundred thousand bytes big?
you don't need know class when need pointer class (or reference class, or few other minor things); when need use class, mere forward declaration not sufficient. it's not enough know "sprite
exists"; it's necessary know how big is, too. , without complete declaration, that's not possible.
Comments
Post a Comment