std::map
is not designed to work with objects which are not copy-constructible. You have two options:
- use
std::shared_ptr<LogFileWriter>
instead of LogFileWriter
as the map value
- use
boost::ptr_map
instead of std::map
If you are managing LogFileWriter
objects with shared pointers already, you should use the first solution, otherwise use the second one.
You insert raw pointers into boost::ptr_map
and its destructor takes care of calling delete
for you when appropriate. Note that the insert
method has a different signature (takes the key as the first parameter and a pointer to the value as the second one) and for some opaque reason you must provide the key as a non-const lvalue reference.
The documentation for boost::ptr_map
is here: http://www.boost.org/doc/libs/1_55_0/libs/ptr_container/doc/ptr_map.html