Covariant callback functions, or assigning base class members through a subclass reference
Rene Zwanenburg via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 14 08:53:09 PDT 2015
On Tuesday, 14 July 2015 at 15:35:04 UTC, Kagamin wrote:
> Template Base on Derived:
>
> class Derived : Base!Derived
> {
>
> }
Sure, but that would make Base!Derived and Base!AnotherSubClass
different types.
What I'd like to end up with is a Base[], being able to call
foo() on the array members. Other parts of the code will add
instances of derived types to this array, and have set the
callback function to a delegate accepting said derived type.
This is part of a library I'm working on. I don't mind if the
library itself contains some nastiness to get this to work, as
long as user code, which defines the derived types, is type safe
and clean.
More information about the Digitalmars-d-learn
mailing list