www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D2 opAssign conflict

reply John C <johnch_atms hotmail.com> writes:
In the latest D2 release, if a struct implements a destructor, the 
compiler automatically defines an opAssign. Unfortunately this causes 
conflicts with user-defined, templated opAssigns.

struct Value {

   void opAssign(T)(T value) {}

   ~this() {}

}

Error: function Value.opAssign conflicts with template Value.opAssign(T)

The first opAssign in the error message is the compiler-generated one. 
If I define multiple non-templated opAssigns, the problem goes away - 
shouldn't we be allowed to have it both ways?

John.
Mar 08 2008
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"John C" <johnch_atms hotmail.com> wrote in message 
news:fqufog$2ncd$1 digitalmars.com...
 In the latest D2 release, if a struct implements a destructor, the 
 compiler automatically defines an opAssign. Unfortunately this causes 
 conflicts with user-defined, templated opAssigns.

 struct Value {

   void opAssign(T)(T value) {}

   ~this() {}

 }

 Error: function Value.opAssign conflicts with template Value.opAssign(T)

 The first opAssign in the error message is the compiler-generated one. If 
 I define multiple non-templated opAssigns, the problem goes away - 
 shouldn't we be allowed to have it both ways?

 John.

Template functions and regular functions are supposed to overload agains each other in D2, but I'm not sure if that's implemented yet. If/when it's implemented I'd imagine that it'd work.
Mar 08 2008