D does not have multiple inheritance like C++. Instead, it follows a Java-style pattern of one base class, multiple interfaces. However, using mixin templates, we can simulate all aspects of multiple inheritance.
We need to execute the following steps to simulate multiple inheritance with mixin templates:
Write an interface and mixin template instead of a base class.
Write your usage class, which inherits from the interfaces and mixes in the mixin templates to the body.
You may override functions from the mixin template by writing new ones with the same name in the
class
body.
The code is as follows:
import std.stdio : writeln; interface Base1 { void foo(); } mixin template Base1_Impl() { void foo() { writeln("default foo impl"); } } interface Base2 { void bar(); void baz(); } mixin template Base2_Impl() { int member; void bar() { writeln("default bar impl"); } void baz() { writeln("default bazimpl"); } } classMyObject...