www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Bug or feature?

reply "Jack Applegame" <japplegame gmail.com> writes:
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)
May 10 2015
next sibling parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
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". Ali
May 10 2015
parent reply Jonathan M Davis via Digitalmars-d-learn writes:
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
May 10 2015
parent "Jack Applegame" <japplegame gmail.com> writes:
Ok, it's a feature. Thanks.
May 10 2015
prev sibling parent Manfred Nowak <svv1999 hotmail.com> writes:
Jack Applegame wrote:

         test(10);      // error
One can "import" the declaration by using an alias: class A { void test(int) {} } class B : A { alias test= super.test; void test() { super.test(1); // compiles test(10); // compiles } } -manfred
May 10 2015