How to initialize a static const map in c++?
- by Meloun
Hi,
I need just dictionary or asociative array string = int.
There is type map C++ for this case.
But I need make one map in my class make for all instances(- static) and this map cannot be changed(- const);
I have found this way with boost library
std::map<int, char> example =
boost::assign::map_list_of(1, 'a') (2, 'b') (3, 'c');
Is there other solution without this lib?
I have tried something like this, but there are always some issues with map initialization.
class myClass{
private:
static map<int,int> create_map()
{
map<int,int> m;
m[1] = 2;
m[3] = 4;
m[5] = 6;
return m;
}
static map<int,int> myMap = create_map();
}
thanks