jeudi 4 août 2016

extern type of string in a header works but a map fails

I have two files in my project common.h and common.cpp

The header file is being used by a lot of files and it contains this statement

extern std::map<std::string,int> lookup ;

Now in the cpp file I did something like this to populate the values in the map

std::map<std::string,int> lookup = {
       {"foo",12}
};

at this point i get a linker error. I would like to know how i can fix this issue. I would like to have a header file with pre populated data this is available to the rest of the code.

Aucun commentaire:

Enregistrer un commentaire