In your case the addition creates a new tempory objects, which will be used with the copy constructor to set x to the value.
The addition operator could look like this:
|
double operator+(const double &, const double &);
|
As you see, it returns a double (a new object, not an reference!). Thats what i meant by temporary object. Thats because sometimes its not wanted to change any of the param. (z = x + y)
But if you use += the compiler know, that he does not need to create a new temp. double, and so its generally faster. (ok with doubles there is no real deal, but since you properbly have 1000 instances...)
So generally, if you CAN, than use += or *=, -=, /= ... etc.
Maikel
Edit: I guess with smart compilers they do sometimes automatic optimations, but you can't be sure.