の値がstd::type_index
であるstd::unordered_map
を作成しようとしています。次のスニペットは動作します:マップの値としてstd :: type_indexを使用します
std::unordered_map<std::type_index, int> workingMap;
workingMap[typeid(int)] = 1;
workingMap[typeid(char)] = 2;
しかし、実行していないこの1つはエラースロー:私は完全にこのエラーを理解していない
std::unordered_map<int, std::type_index> failingMap;
failingMap[1] = typeid(int);
failingMap[2] = typeid(char);
CS2512: 'std::type_index::type_index': no appropriate default constructor available.
を、コンストラクタの違いは何ですかこれらの例では?キーの代わりにtypeid(..)
が値のマップを作ることはできますか?
行うことによって、 'それがマップに見つからなかった場合failingMap [1]'デフォルトのエントリを作成します。 ':: try_emplace'を使用してください。 – Sopel