恒图初始化在C++

问题描述:

可能重复:
Initializing a static std::map<int, int> in C++恒图初始化在C++

我本善良地图:

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

但在VS 2005中,当我运行

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

测试

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 

我怎样才能解决这个问题?或者以最有效的方式定义具有常量已知值的映射的最佳方法是什么?

+0

整个负载的重复。 – 2012-02-10 11:02:53

+1

看看这里:http://*.com/questions/138600/initializing-a-static-stdmapint-int-in-c – Nick 2012-02-10 11:03:36

+0

嘿看看这个[* question](http://*.com/questions/2636303/how-to-initialize-a-static-const-map-in-c) [1]:http://*.com/questions/2636303/how-to-initialize-a- static-const-map-in-c – fizzbuzz 2012-02-10 11:07:55

为什么不使用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'); 
+0

我很想,我不能 – 2012-02-10 11:06:27

+0

加油!这是一个确切的副本http://*.com/questions/138600/initializing-a-static-stdmapint-int-in-c – Nick 2012-02-10 11:06:49

+0

@YpsilonIV:为什么不呢? – 2012-02-10 11:07:45