Override with function overloads

jmh530 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Sep 10 20:14:25 PDT 2017


In the code below, the second to the last line fails to compile. 
As far as I can tell it is because the override also overrides 
all overloads. I could imagine why it would occur with a virtual 
member function, but I would think it wouldn't be necessary with 
a final one.

@system
unittest
{
     class Foo
     {
         final string bar(double d) { return ""; }
         void bar(int x) { x++; };
     }

     class Foo2 : Foo
     {
         override void bar(int x) { }
     }

     Foo2 foo2 = new Foo2;
     foo2.bar(1);
     string x = foo2.bar(1.0); //error that bar is not callable 
with doubles
     //string x = foo2.Foo.bar(1.0); //this compiles
}


More information about the Digitalmars-d-learn mailing list