Multiple Inheritance with template 'bolt-ins'
Part of TemplatesCategory
Description
I've been experimenting a little, most of this is taken from Andy Freisens streams.d which doesn't appear to be on the web anymore. His is a very good example, this is trivial please expand on it!
Example
import std.c.stdio; interface Vehicle { void drive(); void stop(); } class Car (T) : T , Vehicle{ void drive() { puts("driving on land");} void stop () { puts("stopping on land"); } void driveOnRoad() { puts("driving on road"); } } class Boat (T) : T , Vehicle { void drive () { puts("driving on water"); } void stop () { puts("stopping on water"); } void floatOnWater() { puts("floating on water"); } } alias Car!( Boat!(Object ) ) CarBoat; alias Boat!( Car!(Object ) ) BoatCar; void main ( ) { CarBoat x = new CarBoat; x.floatOnWater(); x.driveOnRoad(); x.drive(); puts("\n"); BoatCar y = new BoatCar; y.floatOnWater(); y.driveOnRoad(); y.drive(); }
Source
Originally posted by Q in March 2004.
Apparently based on D:25856.
