'final' function implementations in interface definition
Robert Clipsham
robert at octarineparrot.com
Sun Jun 7 15:44:59 PDT 2009
HOSOKAWA Kenchi wrote:
> Robert Clipsham Wrote:
>
>> If you want this then you need abstract classes.
>> http://www.digitalmars.com/d/1.0/attribute.html#abstract
>>
>> abstract class A
>> {
>> abstract void f(int);
>> final void f_twice(int i) { f(i); f(i); }
>> }
>>
>> class B : A { }
>>
>> (new B).f_twice(1);
>
> Unfortunately the derived class have already inherited another class in my code.
> I need interface inheritance.
>
You could use a template mixin then:
template MyInterfaceMethods()
{
final void f_twice( int i ) { f(i); f(i); }
}
interface I
{
void f( int );
}
class A : I
{
mixin MyInterfaceMethods;
}
More information about the Digitalmars-d
mailing list