In short, you cannot use C ++ 98 / C ++ 03. Objects in objVector are allocated and owned by objVector, and when you destroy or clean it, objects will also be destroyed.
With C ++ 11, you can implement a move constructor for your object and populate ptrVector with new objects that were moved along the way from objects to objVector. In general, move constructors move private members of an object, avoiding a copy of any large data structure distributed by the heap that belong to the object, which is usually very cheap.
To do this, you should use something like std::transform(begin(objVector), end(objVector), std::back_inserter(ptrVector), [](object& o){return new object(std::move(o);})
However, I recommend making ptrVector a std::vector<std::unique_ptr<object>> or std::vector<std::shared_ptr<object>> instead of using a raw pointer if ptrVector has exclusive or joint ownership of the objects to which it indicates accordingly.
source share