Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
May 10, 2015 Bug or feature? | ||||
---|---|---|---|---|
| ||||
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 Re: Bug or feature? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack Applegame | 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 Re: Bug or feature? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack Applegame | 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 Re: Bug or feature? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | 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 Re: Bug or feature? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | Ok, it's a feature. Thanks. |
Copyright © 1999-2021 by the D Language Foundation