Since you need to insert a pair
to the map, you can also use emplace
instead of insert
, so it will construct the pair
in-place with the given key and value.
https://en.cppreference.com/w/cpp/container/unordered_map/emplace
map.emplace("string", std::make_shared<ClassB>());