Just wondering if there is a way to move an object holding a unique_ptr into a vector of those objects? Example:
class A
{
public:
std::unique_ptr<someData> ptr;
};
std::vector<A> objects;
A myObject;
//move myObject to objects???
Now, is there a way I could move myObject into objects and avoiding unique_ptr errors?
You'll need to do std::move
:
std::vector<A> objects;
A myObject;
objects.push_back(std::move(myObject));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.