There are two classes Base and Derived. Base.h:
class Base {
public:
Base* create_obj();
};
And Base.cpp :
#include "Base.h"
Base* Base::create_obj() {
return new Derived();
};
and Derived.h :
#inlcude "Base.h"
class Derived : public Base {
};
If the two classes were in main.cpp
then there would be no error. But when I put them in multiple files like above I get this error :
Cannot initialize return object of type 'Base *' with an rvalue of type 'Derived *'
Why is that? How can I fix this error?