You can't, boost::scoped_ptr
is non-copyable by design (emphasis mine):
The scoped_ptr template is a simple solution for simple needs. It supplies a basic "resource acquisition is initialization" facility, without shared-ownership or transfer-of-ownership semantics. Both its name and enforcement of semantics (by being noncopyable) signal its intent to retain ownership solely within the current scope.
<...>
scoped_ptr cannot be used in C++ Standard Library containers. Use shared_ptr if you need a smart pointer that can.
You can, however, emplace shared_ptr
s into a container, since in this case no copying is performed:
std::list<boost::scoped_ptr<MyClass>> list;
list.emplace_back(new MyClass());