So for some reason this works in a class contructor but not outside a class I was wondering as to why and how could I get my map to work outside a class.
#include <iostream>
#include <string>
#include <map>
typedef std::map <std::string, int> idMap;
idMap type_id;
type_id["Moon"] = 1;
type_id["Star"] = 2;
type_id["Sun"] = 3;
int main()
{
std::cout << type_id["Moon"] << std::endl;
}
The compiler errors I get are as follows
11:1: error: 'type_id' does not name a type 12:1: error: 'type_id' does not name a type 13:1: error: 'type_id' does not name a type
I am looking for an example like this that would work, also if you can tell me why this won't work.