I am wondering if the following is a safe way of returning a deep vector
of objects.
class MyClass {
//...
}
std::vector<MyClass> get_list(a,b,c) {
// obj is created on the stack
MyClass obj(a,b,c);
std::vector<MyClass> objects();
objects.push_back(obj);
// objects[0] contains a pointer to a stack variable?
return objects
}
In particular, how does the returned vector not contain a reference to a stack memory location?