digitalmars.D.learn - Satisfying interface requirements
- Jason House (5/5) Jul 26 2007 Attached is a simple example that demonstrates my problem (with dmd 1.01...
- Chris Nicholson-Sauls (16/23) Jul 26 2007 The standard technique is to use an alias, like so:
- Jason House (3/38) Jul 26 2007 For whatever reason, that trick didn't work for me. I got the same
- BCS (3/6) Jul 27 2007 could you post code?
- BCS (5/18) Jul 26 2007 alias the functions (I think you can even change the name to make it mat...
Attached is a simple example that demonstrates my problem (with dmd 1.018). It seems like inheriting from a class that contains functions that would satisfy an interface does not work. Usually, I work around this by just adding a manual call to super's copy. Unfortunately, this only works if super's member function is not final. Any tips on how to work around this? If line 7 is commented out: test.d(6): class test.foo interface function bar.start is not implemented If line 7 is present: test.d(7): function test.foo.start cannot override final function tango.core.Thread.Thread.start
Jul 26 2007
Jason House wrote:Attached is a simple example that demonstrates my problem (with dmd 1.018). It seems like inheriting from a class that contains functions that would satisfy an interface does not work. Usually, I work around this by just adding a manual call to super's copy. Unfortunately, this only works if super's member function is not final. Any tips on how to work around this? If line 7 is commented out: test.d(6): class test.foo interface function bar.start is not implemented If line 7 is present: test.d(7): function test.foo.start cannot override final function tango.core.Thread.Thread.startThe standard technique is to use an alias, like so: interface Foo { int bar(); } class A { int bar(); } class B : A, Foo { alias A.bar bar; } Although, personally, I'm not entirely satisfied with this. I would think checking for interface implementation warrants a look up the inheritance chain. I think there was a reason given in an older discussion, but darned if I can remember it now. -- Chris Nicholson-Sauls
Jul 26 2007
Chris Nicholson-Sauls wrote:Jason House wrote:For whatever reason, that trick didn't work for me. I got the same error as if I hadn't had the alias in there at all.Attached is a simple example that demonstrates my problem (with dmd 1.018). It seems like inheriting from a class that contains functions that would satisfy an interface does not work. Usually, I work around this by just adding a manual call to super's copy. Unfortunately, this only works if super's member function is not final. Any tips on how to work around this? If line 7 is commented out: test.d(6): class test.foo interface function bar.start is not implemented If line 7 is present: test.d(7): function test.foo.start cannot override final function tango.core.Thread.Thread.startThe standard technique is to use an alias, like so: interface Foo { int bar(); } class A { int bar(); } class B : A, Foo { alias A.bar bar; } Although, personally, I'm not entirely satisfied with this. I would think checking for interface implementation warrants a look up the inheritance chain. I think there was a reason given in an older discussion, but darned if I can remember it now. -- Chris Nicholson-Sauls
Jul 26 2007
Reply to Jason,For whatever reason, that trick didn't work for me. I got the same error as if I hadn't had the alias in there at all.could you post code? what version are you using?
Jul 27 2007
Reply to Jason,Attached is a simple example that demonstrates my problem (with dmd 1.018). It seems like inheriting from a class that contains functions that would satisfy an interface does not work. Usually, I work around this by just adding a manual call to super's copy. Unfortunately, this only works if super's member function is not final. Any tips on how to work around this? If line 7 is commented out: test.d(6): class test.foo interface function bar.start is not implemented If line 7 is present: test.d(7): function test.foo.start cannot override final function tango.core.Thread.Thread.startalias the functions (I think you can even change the name to make it match) interface I {int foo();} class C { int bar(){...} } class D : C, I {alias bar foo;}
Jul 26 2007