I am new to C++ programming, and i currently working on operator overloading.
I modify one sample code in order to see which constructor and which deconstructer runs.
the code is below
Because you passed b by value, so a copy is made. When operator+ returns the copy is destroyed, hence "Deconstructor runs b".
When you pass by const reference, b isn't copied and results in
MyClass overloaded constructor runs a
MyClass overloaded constructor runs b
MyClass constructor runs
MyClass constructor runs
Deconstructor runs
Deconstructor runs
55
Deconstructor runs
Deconstructor runs b
Deconstructor runs a