tardy v0.0.1 - Runtime polymorphism without inheritance

Atila Neves atila.neves at gmail.com
Wed Jun 17 11:46:12 UTC 2020


On Wednesday, 17 June 2020 at 11:31:09 UTC, jmh530 wrote:
> On Wednesday, 17 June 2020 at 10:04:59 UTC, Atila Neves wrote:
>>[...]
>
> Cool.
>
>> [...]
>
> If I'm understanding you correctly, you could modify 
> Polymorphic (and a similar change to VirtualTable) to
>
> struct Polymorphic(Interface, InstanceAllocator = 
> DefaultAllocator)
>     if(is(Interface == interface) || is(Interface == class) || 
> is(Interface == struct))
>
> and the current functionality would still work.
>
> However, compared to normal inheritance, it would be missing 
> the "base" class's member variables that don't exist in the 
> "derived" one. You also couldn't call the "base" class member 
> functions. Polymorphic is assuming the member functions are all 
> implemented in the instance passed to it, correct?

I think these questions are good motivators for making it 
interface-only since then I don't have to check for data 
definitions.



More information about the Digitalmars-d-announce mailing list