Hello All,
I have case where I create one instance of a class "Base" and there are various other child objects that I need to create ("Derived" from "Base"). Is there a pattern where I could ensure that once I create a base class instance in memory, all derived classes refer the same base instance ?
class Base{
//..functions etc
}
class Derived: public Base{
//Needs all functionality of Base...
//Overrides a few methods of Base ..
}
Now i first create a Base* pB = new Base();
I need to create a large number of derived objects and wanted to ensure that everytime I do a Derived* pD = new Derived(); I create the derived object and the base object but the base always refers to the exact same instance of "base" created right at the beginning.
I hope this does not sound confusing. Apologies for the same if it is.
Kindly let me know your comments.
Thanks,
Deepak