On Tuesday, 1 April 2014 at 09:12:41 UTC, John Colvin wrote:
Also, bear in mind that polymorphism is one-way: you can call base class methods through an inherited class reference, but not the other way around.


Sorry, I should clarify that:

Given an inheritance tree with the base class class at the bottom, calls can always be made down the tree (inheriting class reference calling method in inherited class), but you can only call up the tree via overriden virtual functions (inherited class reference calling inheriting class functions).

A new method that isn't present in the base class is by definition not overriding anything in the base class. Therefore you cannot call it from a base class reference, that would mean moving up the inheritance tree.

Reply via email to