passing subclass to superclass where parameter is a delegate for the superclass
    Chris Bare 
    chris at bareflix.com
       
    Wed Nov 14 16:06:21 UTC 2018
    
    
  
If I have:
class base
{
     void delegate(base) stored_dg;
     void
     add_function (void delegate (base) dlg)
     {
         stored_dg = dlg;
     }
}
class A : base
{
     this ()
     {
         super ();
         add_function (&this.foo);
     }
     void foo (A a)
     {
         log ("i got here");
     }
}
it fails because foo(A) does not match the parameter type of 
delegate(base)
If I change foo (A a) to foo (base a)
It works, but this could be awkward in a deeper class hierarchy 
where you
might not know the class name to use.
Is there a way to do this where foo's parameter type does not to 
match the
class that implements add_function?
Thanks,
Chris
    
    
More information about the Digitalmars-d-learn
mailing list