Constructor call must be in a constructor
Loopback
elliott.darfink at gmail.com
Wed Jul 6 13:10:51 PDT 2011
Hi!
While implementing and overloading several different operators for my
structure I've got stuck with an error.
As noticed in the attachment, in my opBinaryRight function I mimic the
opBinary (left) operator by instantiating the structure itself to avoid
implementing duplicates of the binary operator overloads.
The opBinaryRight operator is defined as following:
DVector2 opBinaryRight(string op, T)(T lhs) if(Accepts!T)
{
// Error: template instance vector.DVector2.__ctor!(DVector2) error
instantiating
return DVector2(lhs).opBinary!op(this);
}
I create an additional DVector2 structure and then calls the opBinary
operator. When creating this DVector2 structure the following
constructor gets called:
this(T)(T arg) if(Accepts!T)
{
static if(isScalar!T)
this(arg, arg);
else
// Error: constructor call must be in a constructor
this(arg.tupleof);
}
As one can clearly see, the constructor call is within a constructor.
Now my questions are; is this a bug with DMD or is it something with my
code example and is there any workarounds/solutions?
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test.d
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20110706/98708063/attachment.ksh>
More information about the Digitalmars-d-learn
mailing list