The problem is not with the shared_ptr
, but with the string
key. Explicit instantiation will solve this problem. You also need to insert a pair
consisting of the key and the value, not a key and a value seperately:
map.insert(std::make_pair (std::string("string"), std::make_shared<ClassB>()));
See also this related answer for a more novel, albiet more complex solution.