I am doing everything correctly as far as I can tell and I have gotten the error message:
error: \'unordered_map\' does not name a type
error: \'mymap\' does
Compile with g++ -std=c++11
(my gcc version is gcc 4.7.2
) AND
#include <unordered_map>
#include <string>
using namespace std;
//global variable
unordered_map<string,int> mymap;
int main() {
mymap.reserve(7000); // <-- try putting it here
return 0;
}
You can't execute arbitrary expressions at global scope
, so you should put
mymap.reserve(7000);
inside main.
This is also true for other STL containers like map and vector.
If you want to support
<unordered_map>
for versions older than c++11 use
#include<tr1/unordered_map>
and declare your maps in the form :-std::tr1::unordered_map<type1, type2> mymap
which will use the technical report 1 extension for backward compatibility.