1

Possible Duplicate:
Initializing a static std::map<int, int> in C++

I this kind of map:

{'V', 'O'}
{'v', 'о'}
{'H', 'В'}
{'h', 'в'}
{'W', 'Ш'}
{'w', 'ш'}

But in VS 2005, when I run for

const static std::map<char, wchar_t> mapDimLetters =
{
    {'V', 'O'},
    {'v', 'о'},
    {'H', 'В'},
    {'h', 'в'},
    {'W', 'Ш'},
    {'w', 'ш'},
}

test

error C2552: 'mapDimLetters' : non-aggregates cannot be initialized with initializer list
1>        'std::map<_Kty,_Ty>' : Types with a base are not aggregate
1>        with
1>        [
1>            _Kty=char,
1>            _Ty=wchar_t
1>        ]
error C2078: too many initializers

How can I fix it? Or what is the best way to define map with constant known beforehand values in the most efficient way?

Community
  • 1
  • 1
Sergei G
  • 1,550
  • 3
  • 24
  • 44
  • 1
    Have a look here: http://stackoverflow.com/questions/138600/initializing-a-static-stdmapint-int-in-c – Nick Feb 10 '12 at 11:03
  • Hey have a look at this [stackoverflow question](http://stackoverflow.com/questions/2636303/how-to-initialize-a-static-const-map-in-c) [1]: http://stackoverflow.com/questions/2636303/how-to-initialize-a-static-const-map-in-c – Aman Aggarwal Feb 10 '12 at 11:07

1 Answers1

1

Why don't you use boost assign?

#include <map>
#include "boost/assign.hpp"
using namespace boost::assign;


const std::map<char, wchar_t> mapDimLetters = map_list_of 
      ('V','O')
      ('v','o')
      ('H','B')
      ('h','b');
Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434