www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - defaulting to blitting when overloading opAssign

reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
With D1, if I define an opAssign for a struct, I can still access the 
blitting version by just assigning to another instance of the same struct.

i.e.:

struct S
{
   int x;
   S opAssign(int n) {x = n; return *this;}
}

void foo(S s)
{
   S s2;
   s2 = s; // ok, just does a bitcopy
}

However, in D2.019 (not sure when this was added), I now get a compile error 
for the assignment statement:

function testit.S.opAssign (int n) does not match parameter types (S)
Error: cannot implicitly convert expression (s) of type S to int

I have to define opAssign(S s).  The docs still say it's not allowed, but 
apparently it is necessary.

Is there any way to call the default bitcopy from this overloaded opAssign, 
or flag that a struct should just be bitcopied when being assigned?

-Steve 
Nov 04 2008
parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
Does nobody have an answer to this?  I guess I'll file a bug report.

-Steve

"Steven Schveighoffer" wrote
 Is there any way to call the default bitcopy from this overloaded 
 opAssign, or flag that a struct should just be bitcopied when being 
 assigned?
Nov 06 2008