interface and class inheritance

Oleg B code.viator at gmail.com
Thu Nov 14 14:17:21 PST 2013


On Thursday, 14 November 2013 at 21:45:11 UTC, Agustin wrote:
> On Thursday, 14 November 2013 at 21:42:38 UTC, Agustin wrote:
>> On Thursday, 14 November 2013 at 21:20:57 UTC, Oleg B wrote:
>>> [code]
>>> import std.stdio;
>>>
>>> interface A { void funcA(); }
>>> class B { final void funcA() { writeln( "B.funcA()" ); } }
>>>
>>> class C: B, A { }
>>>
>>> void main()
>>> {
>>>   auto c = new C;
>>>   c.funcA();
>>> }
>>> [code/]
>>>
>>> $ dmd -run interface.d
>>> interface.d(6): Error: class interface.C interface function 
>>> 'void funcA()' is not implemented
>>>
>>> if swap A and B
>>> [code]
>>> class C: A, B { }
>>> [code/]
>>>
>>> $ dmd -run interface.d
>>> interface.d(6): Error: class interface.C base type must be 
>>> interface, not interface.B
>>>
>>> how to workaround this without change in class B and 
>>> interface A?
>>
>> Try
>>
>> interface A {
>>  final void funcA();
>> }
>> class B {
>>  final void funcA() { writeln( "B.funcA()" ); }
>> }
>>
>> class C: B, A { }
>
> Oh sorry i mean
>
> interface A {
>   void funcA();
> }
>
> class B : A {
>   final void funcA() { writeln( "B.funcA()" ); }
> }
>
> class C : B {
> }

we can't change anything in class B


More information about the Digitalmars-d-learn mailing list