Calling Base Class Overriden Methods

Kenji Hara k.hara.pg at gmail.com
Mon Nov 18 23:54:36 PST 2013


On Monday, 18 November 2013 at 19:36:07 UTC, Jeroen Bollen wrote:
> On Monday, 18 November 2013 at 19:34:56 UTC, Adam D. Ruppe 
> wrote:
>> To do it from outside the class, you write the class name:
>>
>> void main() {
>>        auto obj = new SubClass();
>>        obj.SuperClass.methodA(); // calls the specific super 
>> method
>> }
>
> Thanks! :D
>
> Why aren't these things in the documentation? :/

http://dlang.org/function#virtual-functions
=========================

To avoid dynamic binding on member function call, insert base 
class name before the member function name. For example:

...


void main() {
   auto d = new D();
   assert(d.foo() == 3);    // calls D.foo
   assert(d.B.foo() == 1);  // calls B.foo
   assert(d.C.foo() == 2);  // calls C.foo
   d.test();
}

=========================

Kenji Hara


More information about the Digitalmars-d-learn mailing list