reimplementing an interface in a derived class
Alex
sascha.orlov at gmail.com
Fri Jan 4 22:41:08 UTC 2019
On Friday, 4 January 2019 at 21:08:24 UTC, Ali Çehreli wrote:
> [...]
> In this case, casting is using the B object through it's A
> interface. The overridden behavior does not change.
Yeah... This was my mistake.
> (Actually, that is possible in languages that support multiple
> inheritance through multiple virtual function pointer tables
> (vtbl) but D does not support that.)
>
> Although I'm getting into implementation details here, I think
> it helps with understanding the semantics. There is only one
> vtbl per class object in D and the function entries are all
> filled in during construction. So, a B object's 'foo' slot in
> that table is filled with B.foo. So, such an object can foo()
> only as a B.
Nice :)
> [...]
> By the way, do you have a use case in mind? Perhaps there are
> other ways to achieve that.
Well, not really. I was just astonished that casting is not _the_
forge tool. Then, I checked, that the type indeed changes and
wondered why the behavior was still from the object before
casting.
But I assume, as in an A-type an A object, as well as a B object,
can be stored, and the creation is under my own control - a use
case would be some corner case... And the default virtual
definition explains the behavior very well...
More information about the Digitalmars-d-learn
mailing list