Move semantics in C++

Hi!

I've tried to understand move semantics in C++, but I'm not sure about it and when an object is moved and what it means to be moved.

Suppose I have a function (some_function) which creates a std::vector<SomeType> on its stack frame, i.e. in its function body. Now this vector would actually be returned from that function, something like:

std::vector<SomeType> result = some_function();

Would the vector created on the function body be returned by value (i.e. a copy of the function's vector would be assigned to result) or it would simply be moved? And what exactly would it mean semantically for the vector in the function's body to be moved to result? Since there are no pointers, it's strange to me to think about moving an object.

Second question: do you think it's better to return the vector like I'm doing above or by passing result as a reference parameter to some_function? Why?

Thanks!

Last edited on
Topic archived. No new replies allowed.