Thread overview | ||||||
---|---|---|---|---|---|---|
|
September 29, 2007 Problem of override | ||||
---|---|---|---|---|
| ||||
Why these code is valid: class A { public char[] test() { return "A"; } } class B : A { } class C : B { public char[] test() { return super.test() ~ " C"; } } But these are not? class A { public char[] test() { return "A"; } } class B : A { public void test(char[] a) { } } class C : B { public char[] test() { return super.test() ~ " C"; } } |
September 29, 2007 Re: Problem of override | ||||
---|---|---|---|---|
| ||||
Posted in reply to Eric Suen | Does this help? Eric Suen schrieb: > > class A { > public char[] test() { > return "A"; > } > } > > class B : A { alias A.test test; > public void test(char[] a) { > } > } > > class C : B { > public char[] test() { > return super.test() ~ " C"; > } > } |
September 29, 2007 Re: Problem of override | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit | Is this the bug of D compiler or the feature of
D language? this will be a big problem for visitor pattern,
for examples, Parser, like:
visit(IfStatement s);
visit(WhileStatement s);
....
So if I want override some of the method, how? that is really weird, Java doesn't has this problem...
Eric
"Frank Benoit" <keinfarbton@googlemail.com>
> Does this help?
>
> Eric Suen schrieb:
>>
>> class A {
>> public char[] test() {
>> return "A";
>> }
>> }
>>
>> class B : A {
> alias A.test test;
>> public void test(char[] a) {
>> }
>> }
>>
>> class C : B {
>> public char[] test() {
>> return super.test() ~ " C";
>> }
>> }
|
September 29, 2007 Re: Problem of override | ||||
---|---|---|---|---|
| ||||
Posted in reply to Eric Suen | Yes, it is not bug it is a feature. :( From http://www.digitalmars.com/d/1.0/function.html "However, when doing overload resolution, the functions in the base class are not considered:" "To consider the base class's functions in the overload resolution process, use an AliasDeclaration:" Also see my postings "override and overload" 13-Nov-06 and "aliasing base methods" from 25-Feb-07 Eric Suen schrieb: > Is this the bug of D compiler or the feature of > D language? this will be a big problem for visitor pattern, > for examples, Parser, like: > > visit(IfStatement s); > visit(WhileStatement s); > ..... > > So if I want override some of the method, how? that is really weird, Java doesn't has this problem... > > Eric > > "Frank Benoit" <keinfarbton@googlemail.com> >> Does this help? >> >> Eric Suen schrieb: >>> class A { >>> public char[] test() { >>> return "A"; >>> } >>> } >>> >>> class B : A { >> alias A.test test; >>> public void test(char[] a) { >>> } >>> } >>> >>> class C : B { >>> public char[] test() { >>> return super.test() ~ " C"; >>> } >>> } > > |
Copyright © 1999-2021 by the D Language Foundation