mixed-in ctor not on par with explicit one?
Shriramana Sharma via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jan 13 01:48:01 PST 2016
Hello and thanks for your reply.
Jacob Carlborg wrote:
> [1] http://dlang.org/spec/template-mixin.html - search for "Alias
> declarations can be used to overload together functions declared in
> different mixins"
But I'm not able to do that with `this`:
mixin template myCtors()
{
this(int i) {}
this(char c) {}
}
struct Test
{
mixin myCtors;
alias this = myCtors.this;
this(string s) {}
}
void main()
{
auto a = Test("hello");
auto b = Test(1);
auto c = Test('c');
}
But I get the error:
<src>(9): Error: identifier expected following '.', not 'this'
<src>(9): Error: cannot use syntax 'alias this = myCtors', use 'alias
myCtors this' instead
Even actually giving the mixin instance an identifier doesn't help:
mixin myCtors!() myCtorsInst;
alias this = myCtorsInst.this;
<src>(9): Error: identifier expected following '.', not 'this'
<src>(9): Error: cannot use syntax 'alias this = myCtorsInst', use 'alias
myCtorsInst this' instead
This is not what alias <> this is supposed to do, right? So how am I
supposed to get the mixed in ctors work?
--
Shriramana Sharma, Penguin #395953
More information about the Digitalmars-d-learn
mailing list