Is it possible to have a function in base class which will have return type as pointer to derived class? the main objective is for later use where you use Base
and Derived
Class to set values.
Base B1;
B1.SetName("nameOfBase");
Derived* D1 = B1.CreateDerived("DerivedFromBase");//CreateDerived method will be in class Base
D1->SetMinPoint(0,1);//this method will be implemented in derived class
D1->SetMaxPoint(4,4);//this method will be implemented in derived class
I am having problem in implementation, i did something like
class Base
{
public:
Base();
bool SetName(char*);//or SetName(string)
Derived* CreateDerived(char*); // or Derived* CreateDerived(string)
~Base();
protected:
char baseName[20];// or string baseName
Derived* derivedPtr[5];
};
class Derived: public Base
{
public:
Derived();
bool SetName(char*);//the name given in Derived* CreateDerived(char*) will be set here
~Derived();
};
when i try to do this and run the program i get errors like
// Derived* CreateDerived(char*); // or Derived* CreateDerived(string)
error C2143: syntax error: missing ';' before '*'
error C4430: missing type identifier: int assumed.