1
vector<int> foo()
{
//do something
...

//define my vector
vector<int> result;

//do something
...

return result;
}

vector<int> v = foo();

I have no idea what happens when tha above function returns. Does it recopy the vector defined in the function once and then destructure it, or does it assign its address directly to v? My understanding is that both approaches are the correct semantics, but clearly there is a performance gap, especially if the vector is particularly large.

Would like to get more detailed information about this issue to help me understand why c++ would choose one of both methods to implement this functionality.

Thanks.

Xu_ict
  • 19
  • 3

0 Answers0