samedi 24 décembre 2016

unordered_map.emplace giving compiler time errors?

I have this container as a member in a class:

std::unordered_map<std::string, Fruit> m_fruits;

I want to add a new element to it in the same class, I've tried 2 ways and both should work based on the example. (on emplace's page) But somewhere I made a mistake. (fruitName is a const std::string& )

m_fruits.emplace(fruitName, Fruit());

Error C2660 'std::pair::pair': function does not take 2 arguments

m_fruits.emplace(std::make_pair(fruitName, Fruit()));

Error C2440 '': cannot convert from 'initializer list' to '_Mypair'

Aucun commentaire:

Enregistrer un commentaire