unordered map
を作成して、n次元のポイントを含むようにしようとしています( スペース)。 std::vector
がstd::map
のキーとなるためのすべての要件を満たしていますが、このコードはコンパイルされないことを理解しています。私は、エラーメッセージの長いリストを取得するが、これは最も問題のようだ:C++でstd :: unordered_mapのキーの型としてstd :: vectorを使用する方法は?
error: no match for call to ‘(const std::hash<std::vector<int> >) (const std::vector<int>&)'.
誰でもグラムの++はstd::vector<int>
がハッシュ可能であることを考えるようには思えない理由についてどのような考えを持っていますか?
#include <vector>
#include <unordered_map>
#include <boost/functional/hash.hpp>
using namespace std;
typedef vector<int> point;
int main()
{
unordered_map<point, int>jugSpace;
vector<int> origin(3, 0);
jugSpace.insert(pair<point,int>(origin, 0));
}
私はキーをベクトルへのポインタにします... – user2717954
@ user2717954、恐ろしいアイデア。 – SergeyA
カスタムクラスタイプをキーとして[C++ unordered \ _map]を複製する可能性があります(http://stackoverflow.com/questions/17016175/c-unordered-map-using-a-custom-class-type-as-the -key) –