oop - C++ Inheritance and Includes -
i'm not brand new c++, i'm not expert... yet :)
i'm trying understand how inheritance works. have class derives base class:
class base {}
and
#include "base.h" class derived : public base {}
in base class i'm trying create static method returns pointer derived class object:
#include "derived.h" class base { static derived* getderived(); }
now thought because static member might able away it, compile time issues complaining derived class not know base object is, though i'm including base.h in derived class. aware of circular dependency, because i'm trying return pointer object figured compiler wouldn't need #include "derived.h", seems does.
any direction on why not way go , instead great appreciated!
(i in java)
yes, case(just return pointer object), compiler wouldn't need #include "derived.h"
, needs forward declaration:
class derived; class base { static derived* getderived(); };
demo: http://ideone.com/onuhgc
Comments
Post a Comment