multiple inheritance

Namespace rswhite4 at googlemail.com
Sun Jul 8 11:17:54 PDT 2012


And finally:

[code]
import std.stdio;

interface Transformable {
public:
	void transform();
}

mixin template _Transform() {
public:
	this() {
		writeln("Transform Ctor");
	}

	void transform() {
		writeln("transformiere");
	}
}

abstract class Transform : Transformable {
	mixin _Transform;
}

abstract class Drawable {
public:
	void draw() {
		writeln("zeichne");
	}
}

class Shape : Drawable, Transformable {
public:
	//mixin Transform;
	mixin _Transform;

	this() {
		writeln("Shape CTor");
	}
}

class Texture : Transform {
public:
	override void transform() {
		writeln("rendere texture");
	}
}

void test_drawable(Drawable d) {
	d.draw();
}

void test_transformable(Transformable t) {
	t.transform();
}

void main() {
	Shape s = new Shape();

	test_drawable(s);
	test_transformable(s);

	Texture t = new Texture();

	//test_drawable(t); // fails as expected
	test_transformable(t);
}
[/code]


More information about the Digitalmars-d-learn mailing list