The problem is the call to the std::map::insert member function with invalid parameters: there are two integer values; but there should be std::pair<int, int> . See Link: std :: map :: insert .
Preferred option
For convenience (just do not repeat the parameters of the map type) create a typedef for the map:
typedef std::map<int, int> IntMap;
std::map has a type definition for std::pair (pair representation) - std::map::value_type . So, for example, if there is std::map<int, int> , then std::map::value_type will be std::pair<int, int> .
Use the constructor std::map::value_type ( IntMap::value_type in this case):
class Row { public: void Row::addNumber(int num, int pos) { m_numMap.insert(IntMap::value_type(num, pos)); } private: typedef std::map<int, int> IntMap; IntMap m_numMap; };
Alternatives:
Use the std::make_pair() function:
#include <utility> ... void Row::addNumber(int num, int pos) { numMap.insert(std::make_pair(num, pos)); }
Use the std::pair constructor directly:
void Row::addNumber(int num, int pos) { numMap.insert(std::pair<int, int>(num, pos)); }
source share