On 01-09-2011 21:27, Timon Gehr wrote:
On 09/01/2011 09:25 PM, Alex Rønne Petersen wrote:
On 01-09-2011 21:08, Alex Rønne Petersen wrote:
Hi,
Consider this:
struct S
{
static S opAssign(int rhs)
{
return S();
}
}
void main()
{
S s;
s = 1;
}
And:
struct S
{
S opAssign(int rhs)
{
return S();
}
}
void main()
{
S s;
s = 1;
}
Both will compile. I don't get it. I can understand it in the case of
the static opAssign, but with the non-static one, what does 'this' refer
to inside opAssign? And why are both seemingly allowed?
- Alex
Somewhat related question: should opAssign return void or return an
actual value? Does it matter? If x = y is rewritten to x.opAssign(y), I
assume it doesn't...
- Alex
It does matter for eg multiple assignment:
a = b = c; // return void and this will not work anymore
Ah, that makes sense! Thanks.
- Alex