Is the following code safe? (I already know that it compiles correctly.)
void Tile::clear() { *this = Tile(); } int main() { Tile mytile; mytile.clear(); }
It might work. It depends on how it is Tile& operator = (const Tile&);implemented. However, there is nothing wrong with assigning a *thisnew value.
Tile& operator = (const Tile&);
*this
, Herb Sutter this . , , . , , , .
this
. , - Tile, ( ), Tile, *this =, undefined.
Tile
*this =
It is safe if your copy instance does nothing contrary.