本文介绍了如何在C ++中创建无序的整数对?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
程序不编译无序的整数对,而是整数。可以在用户定义的类型上使用unordered_set及其成员函数,以及如何定义它?
The program does not compile an unordered set of pairs of integers, but it does for integers. Can unordered_set and its member functions be used on user defined types, and how can I define it?
#include <unordered_set> ... class A{ ... private: std::unordered_set< std::pair<int, int> > u_edge_; }; error: no matching function for call to 'std::unordered_set<std::pair<unsigned int, unsigned int> >::unordered_set()'推荐答案
在VS2010 SP1(VC10),但它无法编译与GCC g ++ 4.7.2。
Your code compiles on VS2010 SP1 (VC10), but it fails to compile with GCC g++ 4.7.2.
但是,你可能要考虑 boost ::哈希从 Boost.Functional 哈希 std :: pair (此外,您的代码也使用g ++编译)。
However, you may want to consider boost::hash from Boost.Functional to hash a std::pair (with this addition, your code compiles also with g++).
#include <unordered_set> #include <boost/functional/hash.hpp> class A { private: std::unordered_set< std::pair<int, int>, boost::hash< std::pair<int, int> > > u_edge_; };更多推荐
如何在C ++中创建无序的整数对?
发布评论