vendredi 18 août 2017

Instantiate an object separately for shared pointer C++

The below code works fine:

std::map<std::string,std::ofstream*> m_jsTabFilesMap;
m_jsTabFilesMap.insert({ listOfTabNames[i], new std::ofstream(jsFilename)});

But if I replace normal pointer with a shared pointer the insert function complaints no overloaded version of the function insert() exists.

std::map<std::string, std::shared_ptr<std::ofstream>> m_jsTabFilesMap;

How do I fix this ? Has it to do with the way I'm instantiating the object using new.

Aucun commentaire:

Enregistrer un commentaire