How to use base class & child class as parameter in one function ?

Vinod K Chandran kcvinu82 at gmail.com
Fri May 22 20:55:45 UTC 2020


On Friday, 22 May 2020 at 20:06:20 UTC, Adam D. Ruppe wrote:
> On Friday, 22 May 2020 at 20:04:24 UTC, Vinod K Chandran wrote:
>> sampleList.Add(New Child(10.5)) Is this possible in D without 
>> casting ?
>
> Direct translation of this code works just fine in D.

Yeah, my bad. I just checked in D. But think inherited type 
difference is a problem in function pointer's parameters only.
alias EvtFuncPtr = void function(EventArgs);
Now, this EvtFuncPtr won't allow any derived classes of EventArgs 
as parameter. That's the problem i am facing. What about a 
template ?

alias EvtFuncPtr = void function(T)(T = EventArgs);
This is not compiled.


More information about the Digitalmars-d-learn mailing list