Template mixin can not introduce overloads
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jun 24 20:53:57 PDT 2015
On Thursday, 25 June 2015 at 03:49:04 UTC, Tofu Ninja wrote:
> Is this intended or is it a bug?
Intended, the mixin template works on the basis of names. This
means that you can override methods from the mixin by writing a
member with the same name - very useful thing - but also means no
overloading happens without an extra step.
The extra step is easy though: alias the name in:
void main(string[] args)
{
Test a;
a.foo(5); // works!
a.foo("4qsda");
}
struct Test
{
mixin testMix tm; // give it a name to reference later
void foo(string y){}
alias tm.foo foo; // alias the mixin thing too
}
mixin template testMix()
{
void foo(int x){}
}
By adding that explicit alias, it tells the compiler that yes,
you do want it added to the set, not completely overridden by
your replacement method.
More information about the Digitalmars-d-learn
mailing list