aliasing superclass constructors

Nick Treleaven ntrel-public at yahoo.co.uk
Wed Dec 26 06:38:41 PST 2012


Hi,
Is there an easy way to forward/expose all the constructors of a parent 
class? Just curious. Here are my attempts:

class EFoo : Exception
{
	//alias typeof(super).this this;	// line 12
	//alias typeof(super).__ctor __ctor;	// line 13
}

uncommenting line 12:
superthis.d(12): Error: identifier expected following '.' instead of 'this'
superthis.d(12): Error: no identifier for declarator typeof(super)
superthis.d(12): Error: semicolon expected to close alias declaration
superthis.d(12): Error: found 'this' when expecting '('
superthis.d(12): Error: basic type expected, not ;
superthis.d(12): Error: found ';' when expecting ')'
superthis.d(17): Error: semicolon expected following function declaration
Compilation failed.

uncommenting line 13:
superthis.d(13): Error: this is not a type

I've got a mixin to work though:

class EFoo : Exception
{
	mixin SuperCtors;
}

mixin template SuperCtors()
{
	this(T...)(T args)
	if (__traits(compiles, {new typeof(super)(args);}))
	{super(args);}
}

But it would be nicer if an alias statement could work to avoid defining 
the mixin in every project that needs it.

Partly I'm interested in this as I'm wondering if 'alias this' conflicts 
with 'normal' alias syntax when aliasing constructors.


More information about the Digitalmars-d-learn mailing list