hash_map的问题,急求教,100分

flyincosmic 2005-07-13 12:33:46
我需要一个hash_map< pair<int,int> , int >的数据结构
#include <utility>
#include <hash_map>


using namespace std;

typedef std::pair<int, int> Edge_Type;
typedef int Map_Type;
typedef std::pair< Edge_Type, Map_Type > Edge;
typedef hash_map< Edge_Type, Map_Type > Edge_Map;

int main()
{
Edge_Map edge_map;
edge_map.insert( std::make_pair( Edge_Type( 2, 2 ), 3 ) );

return 0;
}

但是运行总是抱错,如果是hash_map<int, int>或者hash_map<int, pair<int, int> >就没有问题,不知是什么原因
错误如下,在vc7.1+stlport调试(不用stlport,错误也是一样的)
------ 已启动生成: 项目: faint, 配置: Release Win32 ------

正在编译...
main.cpp
main.cpp(32) : warning C4267: “参数” : 从“size_t”转换到“unsigned int”,可能丢失数据
d:\software\STLPort\stlport\stl\_hashtable.h(566) : error C2064: 项不会计算为接受 1 个参数的函数
d:\software\STLPort\stlport\stl\_hashtable.h(565) : 编译类模板成员函数“_STL::hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>::size_type _STL::hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>::_M_bkt_num_key(const _STL::hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>::key_type &,size_t) const”时
with
[
_Val=_STL::pair<const Edge_Type,Map_Type>,
_Key=Edge_Type,
_HF=_STL::hash<Edge_Type>,
_ExK=_STL::_Select1st<_STL::pair<const Edge_Type,Map_Type>>,
_EqK=_STL::equal_to<Edge_Type>,
_All=_STL::allocator<_STL::pair<const Edge_Type,Map_Type>>
]
d:\software\STLPort\stlport\stl\_hash_map.h(56) : 参见对正在编译的类模板实例化“_STL::hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>”的引用
with
[
_Val=_STL::pair<const Edge_Type,Map_Type>,
_Key=Edge_Type,
_HF=_STL::hash<Edge_Type>,
_ExK=_STL::_Select1st<_STL::pair<const Edge_Type,Map_Type>>,
_EqK=_STL::equal_to<Edge_Type>,
_All=_STL::allocator<_STL::pair<const Edge_Type,Map_Type>>
]
main.cpp(27) : 参见对正在编译的类模板实例化“_STL::hash_map<_Key,_Tp>”的引用
with
[
_Key=Edge_Type,
_Tp=Map_Type
]

生成时间 0:01
faint - 1 错误,1 警告



...全文
123 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
oyd 2005-07-13
  • 打赏
  • 举报
回复
因为对于std::pair<int, int> 没有默认的hash函数,需要你自己去定义一个。
flyincosmic 2005-07-13
  • 打赏
  • 举报
回复
谢谢指点

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧