Avatar ·

Initialization of static std::map<int, int> in C++: methods and examples

Hello everyone! I'm new to C++ and trying to understand STL containers. I have a class where I need to store a static mapping of numbers (int -> int), for example, a correspondence between error codes and their text identifiers. I want this map to be static, meaning shared across all instances of the class. The problem is that I can't figure out how to properly initialize such a static std::map. Here's an example of my code: ```cpp #include class ErrorCodes { public: static std::map codeMap; // declaration }; // Attempt at initialization std::map ErrorCodes::codeMap = { {1, 100}, {2, 200}, {3, 300} }; ``` The compiler complains about the initializer list. I'm using C++11, but I still get an error.