digitalmars.D.learn - Problem of override
- Eric Suen (28/28) Sep 29 2007 Why these code is valid:
- Frank Benoit (3/20) Sep 29 2007 alias A.test test;
- Eric Suen (10/30) Sep 29 2007 Is this the bug of D compiler or the feature of
- Frank Benoit (9/45) Sep 29 2007 Yes, it is not bug it is a feature. :(
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"; } }
Sep 29 2007
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"; } }
Sep 29 2007
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"; } }
Sep 29 2007
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"; } }
Sep 29 2007