I am trying to add unique pointer to map.
auto monkey= std::unique_ptr<Animal> (new Animal(1,"Tom"));
std::map<int, std::unique_ptr<const Animal>> animals; //Map of animals
animals.insert(pair<int, unique_ptr<Animal>>(1,monkey)); // Error here
Error:error: no matching function for call to 'std::pair<int, std::unique_ptr<Animal> >::pair(int&, std::unique_ptr<Animal>&)'
what would be the way to add it ??
myMap.insert(std::make_pair(0, std::unique_ptr<Class1>(new Class1())));on your exampleanimals.insert(pair<int, unique_ptr<Animal>>(1,std::move(monkey)));unique_ptr can be only moved, not copied.