June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
38
Task/Inheritance-Multiple/D/inheritance-multiple-3.d
Normal file
38
Task/Inheritance-Multiple/D/inheritance-multiple-3.d
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
class A {
|
||||
string foo() {
|
||||
return "I am an A.";
|
||||
}
|
||||
}
|
||||
class B {
|
||||
string foo() {
|
||||
return "I am a B.";
|
||||
}
|
||||
}
|
||||
|
||||
class C : A {
|
||||
string className = "C";
|
||||
override string foo() {
|
||||
return "I am a "~className~", and thus an A.";
|
||||
}
|
||||
@property
|
||||
BWrapper asB() {
|
||||
return new BWrapper();
|
||||
}
|
||||
alias asB this;
|
||||
class BWrapper : B {
|
||||
override string foo() {
|
||||
return "I am a "~className~", disguised as a B.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unittest {
|
||||
import std.stdio : writeln;
|
||||
|
||||
auto c = new C();
|
||||
A a = c;
|
||||
B b = c;
|
||||
|
||||
writeln(a.foo());
|
||||
writeln(b.foo());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue