I've got a question concerning handling of virtual function in C++ programming. I have something like this:
template<class T>
class baseClass
{
virtual void doSomething(T& t) {
// some baseClass specific code
}
void doSomethingElse(T& t) {
// some baseClass specific code
this->doSomething(t);
}
}
template<class T>
class subClass
{
virtual void doSomething(T&) {
// some subclass related code
}
}
Now, if I construct an object of type subClass....
int main(int argc, char *argv[])
{
subClass<anyType> * subClassObject = new subClass<anyType>();
subClassObject->doSomethingElse(anyTypeObject);
}
.... and call the doSomethingElse
method of the base class, this method will call the doSomething
method of the base class and not of the sub class.
What I want to have, is calling the doSomething
method of the subclass (not of the baseClass
).
Can anybody tell me how to accomplish that?