digitalmars.D.learn - Constructor call must be in a constructor
- Loopback (27/27) Jul 06 2011 Hi!
- Jesse Phillips (2/34) Jul 06 2011 This is probably related to a question recently asked on SO, which you m...
- Don (6/42) Jul 07 2011 Bizarrely, the bit about template constructors was added to the docs as
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?
Jul 06 2011
Loopback Wrote: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); } [Blah, blah, blah]This is probably related to a question recently asked on SO, which you might have even been the author. But for synergy: http://stackoverflow.com/questions/6553950/how-to-use-template-constructors-in-d
Jul 06 2011
Jesse Phillips wrote:Loopback Wrote:Bizarrely, the bit about template constructors was added to the docs as part of the fix to bug 2616. Yet, bug 435 "Constructors should be templatized" is still open. In view of this confusion, I would expect that compiler bugs related to this feature are very likely. Please submit a bug report.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); } [Blah, blah, blah]This is probably related to a question recently asked on SO, which you might have even been the author. But for synergy: http://stackoverflow.com/questions/6553950/how-to-use-template-constructors-in-d
Jul 07 2011