I'm going to try and dumb this question down a little:
Essentially, I have 3 classes -- two derived classes and a base class that contains mutual member functions.
viz.
BaseClass
/\
/ \
/ \
Derived1 Derived2
The problem is that I would like to instantiate the derived class(es) as such:
BaseClass *MyClass;
if (SomeCondition)
{
MyClass = new Derived1;
}
else
{
MyClass = new Derived2;
}
MyClass->DoFunction1;
MyClass->DoFunction2;
MyClass->DoFunction3;
...And utilize "MyClass" in such a way that it remains generic -- moreover, "MyClass" will execute (overridden) functions that are either of type "Derived1" or "Derived2" depending on the "SomeCondition" above.
Sounds like a simple implementation of class inheritance? Here's where it gets complicated: Derived1 and Derived2 need to look exactly like BaseClass in order for BaseClasses virtual functions to be overridden. Fine. But Derived1 and Derived2 have their own specialized functions, which shouldn't necessarily be declared in the interface for BaseClass. But wait, in order to keep the "MyClass" variable generic, we cannot have this kind of specialization without including it in BaseClasses interface -- thus the specialization is destroyed. Assume that all of the functions for Derived1 and Derived2 are now included in the interface for BaseClass (which is mandatory, since Derived1 and Derived2 must look like BaseClass) and we try to hide Derived1's specialized functions from Derived2 and vise-versa. We can try to accomplish this by declaring the functions "private". But wait, if we use the MyClass variable, it still has access to the "private parts" -- the only way to hide them is to create classes that inherit from Derived1 and Derived2, and then instantiate these descendents.
Question: Can I keep "MyClass" generic and still have specialized functions that are unique to Derived1 or Derived2. Is there some other methodology that is superior, without all of the "duct tape" ?