恒图初始化在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
我怎样才能解决这个问题?或者以最有效的方式定义具有常量已知值的映射的最佳方法是什么?
为什么不使用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');
我很想,我不能 – 2012-02-10 11:06:27
加油!这是一个确切的副本http://stackoverflow.com/questions/138600/initializing-a-static-stdmapint-int-in-c – Nick 2012-02-10 11:06:49
@YpsilonIV:为什么不呢? – 2012-02-10 11:07:45
整个负载的重复。 – 2012-02-10 11:02:53
看看这里:http://stackoverflow.com/questions/138600/initializing-a-static-stdmapint-int-in-c – Nick 2012-02-10 11:03:36
嘿看看这个[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 – fizzbuzz 2012-02-10 11:07:55