c++ - Forward declare a subclass that inherits from a class in different namespace -
i don't understand why fails compile:
#include <sometype.h> // has namespace called somenamespace class myapplication; int main(...) { ... myapplication application; ... } class myapplication : public somenamespace::sometype { ... };
as stands i'm getting error g++ (ubuntu 4.4.3-4ubuntu5) 4.4.3
../fix-protocol/main.cpp:44: error: aggregate ‘myapplication application’ has incomplete type , cannot defined
in main
you're instantiating object of type myapplication
, still incomplete type; can't that, since compiler doesn't know yet (it need know e.g. how big it, if has constructor, ...).
to solve problem, have define myapplication
before instantiating objects of type. place class definition in separate header name, #include
d in file needs it.
forward declarations, instead, in general used break cyclic dependencies , other scenarios of kind; "there's class named that", create incomplete type, can used declare variables of type, not define them.
Comments
Post a Comment