September 22, 2004
Hi,

Maybe this is more a limitation or inconsistency than a bug, but anyway.

In a class, I can use a mixed in constructor.
When multiple mixins define a function with the same name, they can be disambiguated with a mixin identifier.
A mixed in constructor can be overridden.

But: when multiple mixins define a constructor, there is no way to use them. The code below gives

override.d(17): identifier expected following '.', not 'this'
override.d(17): identifier expected following '.', not 'this'

Commented out is a working constructor that uses mixed in functions, the same way as I want to use mixed in constructors.


#template Foo()
#{
#	void func() { printf("Foo.func().\n"); }
#	this() { printf("Constructing Foo.\n"); }
#}
#
#template Bar()
#{
#	void func() { printf("Bar.func().\n"); }
#	this() { printf("Constructing Bar.\n"); }
#}
#
#class FooBar
#{
#	mixin Foo F;
#	mixin Bar B;
#	this()
#	{
#		printf("Constructing FooBar.\n"); F.this(); B.this();
#	}
#	/*
#	this()
#	{
#		printf("Constructing FooBar.\n"); F.func(); B.func();
#	}
#	*/
#}
#
#void main()
#{
#	FooBar fb = new FooBar();
#}

It has its application in achieving multiple inheritance (derive from multiple interfaces and mix in multiple implementations, then override conflicting functions and merge their functionality). The limitation can be worked around by taking the contents of constructors out in, say func(), and use the part that is commented out above in stead.

Bastiaan.