1
const unordered_map
を宣言したいが、コンパイラエラーが発生し、正しい構文がわからない。私が見つけたすべての例ですが、1つは非constです。私が知っている唯一のconstの例と同じようにしていますが、コンパイラエラーが発生します。ここに私のコードは次のとおりです。"const unordered_map"の使い方は?
typedef const std::unordered_map<std::string,int> StringIntMap;
StringIntMap string_to_case {
{"get",1},
{"add",2}
};
は私を与える:
Error 1 error C2601: 'string_to_case' : local function definitions are illegal
または私はstring_to_case
間の等号を入れて、私が手ブラケットの場合:120_CTP_Nov2012対
Error 1 error C2552: 'string_to_case' : non-aggregates cannot be initialized with initializer list
ではなくなります私は等号の有無にかかわらず次のようにします:
error C2440: 'initializing' : cannot convert from 'initializer-list' to 'std::unordered_map<std::string,int,std::hash<_Kty>,std::equal_to<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>'
1> with
1> [
1> _Kty=std::string
1> , _Ty=int
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
何が間違っていますか?
ありがとうございますが、ビジュアルスタジオ(少なくともvs2012アップデート5とvs2012 CTPノベル2012)、どちらも受け付けません:( – AbsolutelyFreeWeb
合意。VS 15以降(コンパイラバージョン19)が必要です。 –
スペアボックスにFedora Linuxの最新バージョンをインストールするには約1時間かかります.gcc 6.1.1はそのままの状態で使用できます。最新のC++標準をサポートする最新のC++コンパイラを使用するには、 –