opAssign for structs
Sean Silva
chisophugis at gmail.com
Fri Oct 21 20:21:09 PDT 2011
In the language definition <http://d-programming-language.org/struct.html>, it says:
> Struct assignment t=s is defined to be semantically equivalent to:
> t = S.opAssign(s);
> where opAssign is a member function of S:
> S* opAssign(S s)
> { ... bitcopy *this into tmp ...
> ... bitcopy s into *this ...
> ... call destructor on tmp ...
> return this;
> }
I'm struggling with this on 4 fronts:
1. What is `this`, when opAssign is called off of the type? (does it even make sense to call a member function without an instance?)
2. The return value of opAssign is `S*`, so it would seem that `t` is assigned a pointer value?
3. What is `tmp`, just another stack allocated instance of S?
4. What is the syntax for explicitly calling the destructor? (In C++, it is tmp.~S(), but in D would it be tmp.~this() or what?)
More information about the Digitalmars-d-learn
mailing list