Thread overview |
---|
October 09, 2002 Two interfaces with same method signatures | ||||
---|---|---|---|---|
| ||||
the follwoing code ... interface D { int foo( int i ); } interface E { int foo( int i ); } class A : D { int foo( int i ) { printf( "A::foo(%d);\n", i ); return 1; } } class B : A, E { int foo( int i ) { printf( "B::foo(%d);\n", i ); return 1; } } class C : B { int foo( int i ) { printf( "C::foo(%d);\n", i ); return 1; } } int main( char[][] args ) { A a = new A(); B b = new B(); C c = new C(); printf( "(cast(D)a).foo( 1 )\n" ); (cast(D)a).foo( 1 ); printf( "(cast(D)b).foo( 2 )\n" ); (cast(D)b).foo( 2 ); printf( "(cast(E)b).foo( 3 )\n" ); (cast(E)b).foo( 3 ); printf( "(cast(D)c).foo( 4 )\n" ); (cast(D)c).foo( 4 ); printf( "(cast(E)c).foo( 5 )\n" ); (cast(E)c).foo( 5 ); return 0; } compiles without warning and outputs (cast(D)a).foo( 1 ) A::foo(1); (cast(D)b).foo( 2 ) B::foo(2); (cast(E)b).foo( 3 ) B::foo(3); (cast(D)c).foo( 4 ) C::foo(4); (cast(E)c).foo( 5 ) C::foo(5); this this by design or should warnings be issued ? (I vote warn me) |
October 10, 2002 Re: Two interfaces with same method signatures | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Wynn | It's by design. I don't understand what the problem is? "Mike Wynn" <mike.wynn@l8night.co.uk> wrote in message news:ao29t3$2o31$1@digitaldaemon.com... > the follwoing code ... > > interface D > { > int foo( int i ); > } > > interface E > { > int foo( int i ); > } > > class A : D > { > int foo( int i ) { printf( "A::foo(%d);\n", i ); return 1; } > } > > class B : A, E > { > int foo( int i ) { printf( "B::foo(%d);\n", i ); return 1; } > } > > class C : B > { > int foo( int i ) { printf( "C::foo(%d);\n", i ); return 1; } > } > > int main( char[][] args ) > { > A a = new A(); > B b = new B(); > C c = new C(); > printf( "(cast(D)a).foo( 1 )\n" ); > (cast(D)a).foo( 1 ); > > printf( "(cast(D)b).foo( 2 )\n" ); > (cast(D)b).foo( 2 ); > > printf( "(cast(E)b).foo( 3 )\n" ); > (cast(E)b).foo( 3 ); > > printf( "(cast(D)c).foo( 4 )\n" ); > (cast(D)c).foo( 4 ); > > printf( "(cast(E)c).foo( 5 )\n" ); > (cast(E)c).foo( 5 ); > > return 0; > } > > compiles without warning and > outputs > > (cast(D)a).foo( 1 ) > A::foo(1); > (cast(D)b).foo( 2 ) > B::foo(2); > (cast(E)b).foo( 3 ) > B::foo(3); > (cast(D)c).foo( 4 ) > C::foo(4); > (cast(E)c).foo( 5 ) > C::foo(5); > > this this by design or should warnings be issued ? (I vote warn me) > > |
October 10, 2002 Re: Two interfaces with same method signatures | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <walter@digitalmars.com> wrote in message news:ao2nag$2nq$1@digitaldaemon.com... > It's by design. I don't understand what the problem is? name clash without warning, I have two interfaces, same signature, which is irrelevent as these are com interfaces, B inherits a D interface from A (behind the scene), implements E and defines a foo for E but D's foo for B is also changed. C then inherits both D and E from B, redefines foo, but which foo D or E or both ?. as a default behviour this is as good as any in this situation IMHO but I think the compiler should issue warnings that B's foo is also changing the inherited D.foo from A if B was declared `class B : A, D, E {int foo(int){...}}` then fine the programmer means or should mean that B's foo is to be put both in D and E again with C it is unclear if the code was intended to redefine foo in both D and E. guess I'm too used to GCC which issues warnings any time it considers that you have writen ambigious code. this is as much a documentation issuse as a semantic issue, BUT how do I do with DMD 0.45 class B : A, E { int E.foo( int i ) { printf( "B::foo(%d);\n", i ); return 1; } } so that B's foo does not change the D interface implementation ? Mike. > "Mike Wynn" <mike.wynn@l8night.co.uk> wrote in message news:ao29t3$2o31$1@digitaldaemon.com... > > the follwoing code ... > > > > interface D > > { > > int foo( int i ); > > } > > > > interface E > > { > > int foo( int i ); > > } > > > > class A : D > > { > > int foo( int i ) { printf( "A::foo(%d);\n", i ); return 1; } > > } > > > > class B : A, E > > { > > int foo( int i ) { printf( "B::foo(%d);\n", i ); return 1; } > > } > > > > class C : B > > { > > int foo( int i ) { printf( "C::foo(%d);\n", i ); return 1; } > > } > > > > int main( char[][] args ) > > { > > A a = new A(); > > B b = new B(); > > C c = new C(); > > printf( "(cast(D)a).foo( 1 )\n" ); > > (cast(D)a).foo( 1 ); > > > > printf( "(cast(D)b).foo( 2 )\n" ); > > (cast(D)b).foo( 2 ); > > > > printf( "(cast(E)b).foo( 3 )\n" ); > > (cast(E)b).foo( 3 ); > > > > printf( "(cast(D)c).foo( 4 )\n" ); > > (cast(D)c).foo( 4 ); > > > > printf( "(cast(E)c).foo( 5 )\n" ); > > (cast(E)c).foo( 5 ); > > > > return 0; > > } > > > > compiles without warning and > > outputs > > > > (cast(D)a).foo( 1 ) > > A::foo(1); > > (cast(D)b).foo( 2 ) > > B::foo(2); > > (cast(E)b).foo( 3 ) > > B::foo(3); > > (cast(D)c).foo( 4 ) > > C::foo(4); > > (cast(E)c).foo( 5 ) > > C::foo(5); > > > > this this by design or should warnings be issued ? (I vote warn me) > > > > > > |
October 10, 2002 Re: Two interfaces with same method signatures | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Wynn | "Mike Wynn" <mike.wynn@l8night.co.uk> wrote in message news:ao3cd9$oul$1@digitaldaemon.com... > this is as much a documentation issuse as a semantic issue, BUT how do I do > with DMD 0.45 > > class B : A, E > { > int E.foo( int i ) { printf( "B::foo(%d);\n", i ); return 1; } > } > > so that B's foo does not change the D interface implementation ? Currently there's no way to do that. |
Copyright © 1999-2021 by the D Language Foundation