Struct inheritance

Derek Fawcus dfawcus+dlang at employees.org
Wed Dec 4 11:10:59 UTC 2024


On Tuesday, 3 December 2024 at 23:18:12 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
>

Sorry, I had Obj-C in mind when I wrote that, and my use of that 
was over 10 years ago; hence my confusion.

So what would your scheme do for the struct equivalent of this, 
assuming it is even compiles:

```d
import std.stdio;

void main() {
     Child child = new Child;
     child.methB();

     writeln();
     Parent parent = child;
     parent.methB;
}

class Parent {
     void methB() {
      	writeln("MethB(P) ", typeof(this).stringof);
	methC();
     }
     void methC() {
      	writeln("MethB(P) ", typeof(this).stringof);
     }
}

class Child : Parent {
     override void methC() {
      	writeln("MethC(C) ", typeof(this).stringof);
     }
}
```

Where the above give this output:

```
$ ldc2 -run class.d
MethB(P) Parent
MethC(C) Child

MethB(P) Parent
MethC(C) Child
```



More information about the dip.ideas mailing list