But that code isn't "nothing", it is "something". That "something" has side effects (it prints some text), which means that your program is doing different things whether there is an extra copy or not (either prints some additional text or doesn't print some additional text), and the compiled can't know if that is important or not to you personally.
The mere fact that you print something means that there is now an observable difference between making the extra copy and not. That may, as SiCrane suggested, very well be the deciding factor for the compiler's ability and/or desire to remove the extra copy. And that could be a problem for you; attempts you make to observe if this extra copy is made or not, could actual end up being the reason why it is made.
I see. I guess I'll have to remove the std::cout statement, then step through with the debugger, and count the deconstructors. That should work right?
On a side note, when it comes to overloading operators I have added them to my header file under the public section.
Now whenever I use a dot operator to call a method or etc I see all of my overloads, which makes sense they are all under the public section.
But I was wondering can I move them so they will not show up?I tried to just move them to the private section but the compiler (visual studio 2013) can't see them.
Is there a way to make them 'private' so they do not show when I use the dot operator?
Also if I overload the operator+ using MyObject as a param and then again with a float as the param. Should the float param be const float?
MyObject &MyObject::operator+=(const MyObject &obj) //Normal overload with MyObject as param
MyObject &MyObject::operator+=(float obj) //Should I use const in the param (const float obj)