defaulting to blitting when overloading opAssign
Steven Schveighoffer
schveiguy at yahoo.com
Tue Nov 4 13:12:39 PST 2008
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
More information about the Digitalmars-d-learn
mailing list