I am a novice at C++, but I am trying to build a std::map
that has an enum
type as value, to avoid fussing with strings.
I have created a minimum example below which does not work
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
enum val_list {Foo, Bar};
int main()
{
std::map<int, val_list> val_map;
std::vector<std::string> dummy_data = {"0","1","3"};
val_map.insert(0,static_cast<val_list>(std::stoi(dummy_data[0])));
}
I get the following compiler error
test.cc:17:66: error: no matching function for call to
‘std::map<int, val_list>::insert(int, val_list)’
17 | val_map.insert(0,static_cast<val_list>(std::stoi(dummy_data[0])));
This toy example is similar to my actual program, which gives me a slightly different error with the same structure
enum PhysicalNames {unassigned,top_points,
side_points, bottom_points, top_lines,
side_lines, bottom_lines, symetry_line,
top_surface,side_surface,bottom_surface};
std::vector<std::string> entity_data;
std::map<int, PhysicalNames> node_map;
node_map.insert(std::stoi(entity_data[0]),group);
This gives me the same error but with a reference variable which is weird
error: no matching function for call to
‘std::map<int, PhysicalNames>::insert(int, PhysicalNames&)’
284 | node_map.insert(std::stoi(entity_data[0]),group);
What am I doing wrong, exactly?