On 09/01/2011 09:08 PM, 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

s = 1;

is rewritten to

s.opAssign(1);

Inside non-static opAssign, therefore 'this' will refer to s.




Reply via email to