如何在C ++中创建无序的整数对?

编程入门 行业动态 更新时间:2024-10-26 22:19:31
本文介绍了如何在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 ++中创建无序的整数对?

本文发布于:2023-11-03 06:53:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554494.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:整数   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!