Why does a directly defined constructor hide a mixed-in constructor?

60rntogo 60rntogo at gmail.com
Sun Sep 13 12:34:06 UTC 2020


This code:

---
mixin template X()
{
   int[2] x;

   this(int[2] x...)
   {
     this.x = x;
   }
}

struct Foo
{
}

struct Bar
{
   mixin X;

   this(Foo foo)
   {
     this.x = [0, 0];
   }
}

void main()
{
   auto bar = Bar(1, 2);
}
---

produces the following error:

---
source/app.d(27,17): Error: constructor app.Bar.this(Foo foo) is 
not callable using argument types (int, int)
source/app.d(27,17):        cannot pass argument 1 of type int to 
parameter Foo foo
---

However, if I directly insert the contents of X into Bar instead 
of mixing it in, it compiles just fine. What's going on here?


More information about the Digitalmars-d-learn mailing list