I have a map with a string key and a struct value, I don't know why I cannot instantiate an object using a list of initializers:
#include <string>
#include <map>
using namespace std;
struct CodeInfo
{
int _level = 0;
bool _reactive;
};
typedef map<string, CodeInfo> CodeInfos; // Key is code name
int main()
{
CodeInfos codes = { {"BARECODE", { 0, true }}, {"BARECODE2", { 0, false }} };
return 0;
}
It seems to be straight forward but I can't understand why I get the following error:
In function 'int main()':
24:80: error: could not convert '{{"BARECODE", {0, true}}, {"BARECODE2", {0, false}}}' from '<brace-enclosed initializer list>' to 'CodeInfos {aka std::map<std::basic_string<char>, CodeInfo>}'
I have using compiler g++ (GCC) 4.9.1 20140922 (Red Hat 4.9.1-10) with C++11.