default ctor myInt(100)
default ctor myInt(200)
default ctor myInt(300)
copy ctor(201)
copy ctor(101)
declaring temp
default ctor myInt(400)
done with declaring temp
about to return temp, myInt(702)
copy ctor(703)
myClass dtor myInt(702)
myClass dtor myInt(101)
myClass dtor myInt(201)
myClass dtor myInt(703)
done with operator+ return from mainFunc()
myClass dtor myInt(703)
myClass dtor myInt(200)
myClass dtor myInt(100)
Press any key to continue . . .
I am trying to get a better understanding of all the constructors, destructors that get called "behind the scenes". I am deliberately passing by value. I don't understand why the destructor for myClass object with myInt=703 gets called the a second time?
I understand that to return "temp 702" a copy 703 is made of it using copy ctor, then temp itself 702 is destructed as we leave operator+ (along with the 2 arguments passed by value 101 and 201) then we set mc3 = mc1 + mc2 using the temporary 703 then we destruct the temporary 703 then we are "done with operator+ return from mainFunc()", and then suddenly why are we calling 703 destructor again??
Argh... kicking myself, it's so obvious now that you say it, I got mixed up since mc3 and temp have the same value (as they should) and mc3 no longer = 300. That was silly of me.