An example of what it looks like:
If you do not see a way out, then copying will occur. This is a copy exception from the initializer. Another legitimate copy case is the return value and is checked:
Foo getFoo() { return Foo(1); } int main() { Foo f = getFoo(); }
or more fun for a named return value:
Foo getFoo() { Foo f(1); return f; } int main() { Foo f = getFoo(); }
g ++ fulfills all these exceptions for me without optimization flags, but you cannot know if the more complex code will exceed the compiler.
Note that the copy exception does not help with the assignment, so when calling operator= following will always be done: if this operator prints something:
Foo f(1); f = getFoo();
Returning by value, it can still lead to "copying", even if the copy constructor query is executed. Thus, in order to classify classrooms, this is still being considered at the design stage. You do not want to write your code in such a way that fixing it later will be of great importance if it turns out that your application spends a significant part of the time on copying, which could be avoided.
source share