Bug or feature?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 10 11:10:59 PDT 2015


On Sunday, May 10, 2015 10:48:33 Ali Çehreli via Digitalmars-d-learn wrote:
> On 05/10/2015 10:18 AM, Jack Applegame wrote:
> > code:
> >
> >> class A {
> >>     void test(int) {}
> >> }
> >>
> >> class B : A {
> >>     void test() {
> >>         super.test(1); // compiles
> >>         test(10);      // error
> >>     }
> >> }
> >
> > Error: function B.test () is not callable using argument types (int)
>
> It is a concept called "name hiding". It is intentional to prevent at
> least "function hijacking".

Yeah. You have to alias A's overloads inside of B or explicitly declare them
as overrides and call the A versions from inside them. So, something like

alias A.test test;

or

alias test = A.test;

inside of B should work (though I haven't done it recently, so the syntax
might be slightly off), or you can just do

override void test(int i) { super.test(i); }

- Jonathan M Davis




More information about the Digitalmars-d-learn mailing list