可能重複:
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
我怎樣才能解決這個問題?或者以最有效的方式定義具有常量已知值的映射的最佳方法是什麼?
整個負載的重複。 – 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