reimplementing an interface in a derived class

kdevel kdevel at vogtner.de
Fri Jan 4 19:55:50 UTC 2019


On Friday, 4 January 2019 at 11:27:59 UTC, Alex wrote:
> On Friday, 4 January 2019 at 09:58:59 UTC, bauss wrote:

[...]

> As for the OP, I think here the usefulness of ", D" should be 
> visible:

[...]

> class B : A, D
> {
>     override int foo() { return 2; }
> }

[...]

>     D d = cast(D) b;
>     assert(d.foo == 2);             // returns 2

If I remove the ", D" the program segfaults in this line:

Program received signal SIGSEGV, Segmentation fault.
0x000000000042c184 in D main () at ggg.d:26
26	    d.foo();
(gdb) p d
$1 = (ggg.D *) 0x0

There is clearly an

    assert (d);

missing in the source. But why is d a null reference in the first 
place?


More information about the Digitalmars-d-learn mailing list