Thread overview |
---|
August 05, 2015 What is the order of resolution for super() calls? | ||||
---|---|---|---|---|
| ||||
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?) |
August 05, 2015 Re: What is the order of resolution for super() calls? | ||||
---|---|---|---|---|
| ||||
Posted in reply to cym13 | 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 ; |
August 05, 2015 Re: What is the order of resolution for super() calls? | ||||
---|---|---|---|---|
| ||||
Posted in reply to cym13 | 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 |
Copyright © 1999-2021 by the D Language Foundation