Template mixin can not introduce overloads
SimonN via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jun 30 10:14:36 PDT 2015
> On Thursday, 25 June 2015 at 03:49:04 UTC, Tofu Ninja wrote:
> > Is this intended or is it a bug?
On Thursday, 25 June 2015 at 03:53:58 UTC, Adam D. Ruppe wrote:
> Intended, the mixin template works on the basis of names. This
> The extra step is easy though: alias the name in:
I would like to to this with constructors instead of normal
methods. I have tried to mix in a constructor as follows:
#!/usr/bin/rdmd
import std.stdio;
mixin template MyConstructor() {
this(int x, float y) { writefln("%d, %f", x, y); }
}
class Base {
mixin MyConstructor my_ctor;
this(string s) { writefln(s); }
alias my_ctor this;
}
void main()
{
Base b = new Base(3, 4.5);
}
$ ./mixinctor.d
./mixinctor.d(17): Error: constructor mixinctor.Base.this (string
s) is not callable using argument types (int, double)
Failed: ["dmd", "-v", "-o-", "./mixinctor.d", "-I."]
Doing it with
alias this = my_ctor;
errors out too, and demands me to use alias my_ctor this; as in
the original code.
Can I get this to work at all? Or does alias this (for multiple
subtyping) fundamentally clash here with alias my_ctor this?
-- Simon
More information about the Digitalmars-d-learn
mailing list