Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
12
Task/Inheritance-Multiple/D/inheritance-multiple-1.d
Normal file
12
Task/Inheritance-Multiple/D/inheritance-multiple-1.d
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
interface Camera {
|
||||
// member function prototypes and static methods
|
||||
}
|
||||
|
||||
interface MobilePhone {
|
||||
// member function prototypes and static methods
|
||||
}
|
||||
|
||||
class CameraPhone: Camera, MobilePhone {
|
||||
// member function implementations for Camera,
|
||||
// MobilePhone, and CameraPhone
|
||||
}
|
||||
12
Task/Inheritance-Multiple/D/inheritance-multiple-2.d
Normal file
12
Task/Inheritance-Multiple/D/inheritance-multiple-2.d
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
interface Camera {
|
||||
// A virtual function.
|
||||
Image takePhoto();
|
||||
|
||||
// A non-virtual function.
|
||||
final Image[] takeSeveralPhotos(int count) {
|
||||
auto result = new Image[count];
|
||||
foreach (ref img; result) {
|
||||
img = takePhoto();
|
||||
}
|
||||
}
|
||||
}
|
||||
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());
|
||||
}
|
||||
19
Task/Inheritance-Multiple/D/inheritance-multiple-4.d
Normal file
19
Task/Inheritance-Multiple/D/inheritance-multiple-4.d
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
template registerable() {
|
||||
void register() { /* implementation */ }
|
||||
}
|
||||
|
||||
string makeFunction(string s) {
|
||||
return `string `~s~`(){ return "`~s~`";}`;
|
||||
}
|
||||
|
||||
class Foo {
|
||||
mixin registerable!();
|
||||
mixin(makeFunction("myFunction"));
|
||||
}
|
||||
|
||||
unittest {
|
||||
import std.stdio : writeln;
|
||||
Foo foo = new Foo;
|
||||
foo.register();
|
||||
writeln(foo.myFunction());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue