reimplementing an interface in a derived class

Alex sascha.orlov at gmail.com
Thu Jan 3 23:44:15 UTC 2019


On Thursday, 3 January 2019 at 23:23:12 UTC, Neia Neutuladh wrote:
> On Thu, 03 Jan 2019 22:30:48 +0000, kdevel wrote:
>> class A : D {
>>      int foo() { return 1; }
>> }
>> 
>> class B : A, D {
>> [...]
>>
>> What is the meaning of the ", D"? It does not seem to make a 
>> difference if it is omitted.
>
> B must provide its own implementation of D. It can't simply use 
> A's implementation.

I assume that is another bug and has nothing to do with 
interfaces...

´´´
import std.traits;

alias parentOfB = BaseClassesTuple!B[0];

void main()
{
	static assert(is(typeof(cast(parentOfB)(new B)) == parentOfB));
	assert((cast(parentOfB)(new B)).foo == (new parentOfB).foo);
}

class A
{
	int foo() { return 1; }
}

class B : A
{
     override int foo() { return 2; }
}
´´´


More information about the Digitalmars-d-learn mailing list