How to dynamically call class virtual method dynamically

John Colvin john.loughran.colvin at gmail.com
Tue Apr 1 02:18:46 PDT 2014


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.


More information about the Digitalmars-d-learn mailing list