*
du********@gmail.com:
Hi, I came across this unexpected behavior while working on something
else. I am attempting to return a custom type by value from a global
function. I have a trace in the custom class's copy constructor, and I
expected this code to tell me that the custom copy constructor had been
called twice. Instead, it's only called once and the program executes
correctly.
Copy constructor calls are allowed to be optimized away -- in many
situations -- regardless of possible side-effects in the copy constructor.
So generally you can't "expect" any specific number of calls.
For your specific example, look up RVO and NRVO.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?