Is there a keyword to access the base class

Ali Çehreli acehreli at yahoo.com
Wed Jun 19 22:13:03 PDT 2013


The OO implementations that I am used to (C++ and D) do not do 
virtualization at the data level. Only member functions are virtual.

One of the reasons is that virtual functions remove the need to know 
what the exact derived type is. The compiler jumps off the virtual 
function pointer table and the actual virtual member function for the 
object gets called.

There are rare cases where the actual derived type may be useful. In 
such cases a series of casts are applied as Steven has shown.

On 06/19/2013 08:35 PM, Stephen Jones wrote:

 > Wouldn't it be easier to simply write bars[1].derived.val and let the
 > compiler look to and accept val if it is declared in the derived class,
 > else gracefully accept val if it is only declared in the base class?

I don't think that implementation has any chance. A statically typed 
language like D will not do that kind of search at runtime. The code 
gets compiled by static types of variables. That's all. If it's a Base, 
it's a Base.

Ali



More information about the Digitalmars-d-learn mailing list