C++ Is the copy constructor called here? -
suppose have functions this:
foo foo() { foo foo; // more lines of code return foo; // copy constructor called here? } foo bar() { // more lines of code return foo(); // copy constructor called here? } int main() { foo = foo(); foo b = bar(); }
when of functions return, copy constructor called (suppose there one)?
it might called, or might not called. compiler has option of using return value optimization in both cases (though optimization bit easier in bar
in foo
).
even if rvo eliminates actual calls copy constructor, copy constructor must still defined , accessible.
Comments
Post a Comment