I have a .h file in which I have created a dictionary as follows :-
map < char, string > mydictionary;
I go on to populate the values as :-
string t = "test";
mydictionary['a'] = "asdf";
mydictionary['b'] = t;
When I try to build the project I get errors for the two lines above mentioning C++ requires a type specifier for all declarations. Unfortunately I find the error message quite cryptic and am not sure about how to approach/solve it.
Why does this error happen? How could I solve this issue?
You can’t put statements at global scope; statements can only go in functions. (Note that this is different from variable initializers, which can go in global scope).
You will need to initialize the map in a function, or, (in C++11), use an initializer list: