Mixin a constructor ?

dsimcha dsimcha at yahoo.com
Sat Sep 19 10:20:40 PDT 2009


== Quote from Jacob Carlborg (doob at me.com)'s article
> Is it supposed to possible to mixin a constructor? The code below
> doesn't compile. The error: is "main.d(23): Error: constructor
> main.A.this() does not match parameter types (int)
> main.d(23): Error: expected 0 arguments, not 1"
> template C ()
> {
> 	this (int i)
> 	{
> 	}
> }
> class A
> {
> 	mixin C;
> 	this ()
> 	{
> 	}
> }
> void main ()
> {
> 	auto a = new A(3);
> }

I'm not sure exactly why this example doesn't work, but it looks like a bug.
Please file.  If you just want to insert a bunch of boilerplate without any
parameters, you probably should try a string mixin instead.  The following does work:

enum string C = q{
    this (int i) {

    }
};

class A {
    mixin(C);

    this () {

    }
}

void main () {
    auto a = new A(3);
}




More information about the Digitalmars-d mailing list