www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - What is the order of resolution for super() calls?

reply "cym13" <cpicard openmailbox.org> writes:
Hi,

I just read 
https://rhettinger.wordpress.com/2011/05/26/super-considered-super/ which
describes how super works in python (tl;dr: it's completely different from C++,
java or D's super but super cool to deal with multiple inheritance).

For example, for the following inheritance tree:

           Object
             /    \
     Adam    Eve
         |   \    /   |
         |     X     |
          \   /   \  /
        Abel   Cain
              \   /
            David

A call in David making use of super would in python go through 
classes in that order:   Abel, Cain, Adam, Eve, Object.  This is 
somewhat peculiar as we don't expect the call of super() in Abel 
to go to Cain just because the initiator was David but that's 
what happens and it is deterministic (I recommend the article to 
see why it is so).

What would be the order in D? Would it be something like:
      Abel
      Adam
      Object
      Eve
      Cain
      (Adam?)
      (Eve?)
      (Object?)
Aug 05 2015
parent reply "cym13" <cpicard openmailbox.org> writes:
Forget it, I just remembered that we only do single inheritance, 
and I don't think the same problem occurs with interfaces.

For reference, as the diagram was unreadable, I'll describe it 
here:

class Adam ;
class Eve ;
class Abel:Adam,Eve ;
class Cain:Adam,Eve ;
class David:Abel,Cain ;
Aug 05 2015
parent "anonymous" <anonymous 12321.23> writes:
On Wednesday, 5 August 2015 at 12:32:48 UTC, cym13 wrote:
 For reference, as the diagram was unreadable, I'll describe it 
 here:

 class Adam ;
 class Eve ;
 class Abel:Adam,Eve ;
 class Cain:Adam,Eve ;
 class David:Abel,Cain ;
This is illegal D. You must use interfaces to simulate multiple inheritance: "D classes support the single inheritance paradigm, extended by adding support for interfaces." see more here: http://dlang.org/class.html
Aug 05 2015