If I have the following code, is the vector copied?
std::vector x = y.getTheVector();
or would it depend on whether the return t
std::vector x = y.getTheVector();
always makes a copy, regardless of the return type of y.getTheVector();.
std::vector& x = y.getTheVector();
would not make a copy. However, x will be valid as long as y.getTheVector() returns a reference to an object that is going to be valid after the function returns. If y.getTheVector() returns an object created in the function, x will point to an object that is no longer valid after the statement.