Consider the following simple polymorphism ...
class Parent {
public:
someFunc() { /* implementation A */ };
};
class Child : public Parent {
public:
someFunc() { /* implementation B */ };
};
int main ()
{
Parent* ptr;
ptr = new Parent();
ptr->someFunc();
delete ptr;
ptr = new Child();
ptr->someFunc();
delete ptr;
return 0;
}
As far as I can tell, in both cases implementation A will be called.
How can I call the "most derived" implementation of someFunc, depending on the dynamic type of ptr?
In my real code there are many children types, so it wouldn't be practical to use dynamic_cast to check per child class.