c++ - GUID 比较器错误!

标签 c++ visual-c++ guid

我编写了以下简单函数 - 一个以 2 个 GUID 作为键和值的无序映射。但是,我认为他们没有定义 GUID 比较器,因此它会在我尝试过的所有 GUID 比较器中抛出此错误。

 #include <unordered_map>
 #include<iostream>
 #include<stdio.h>
 #include<Objbase.h>
 typedef unordered_map<GUID, GUID, less_guid> Mymap;
 Mymap c1;

 int __cdecl wmain(int /*argc*/, __in_ecount(argc) WCHAR * /*argv[ ]*/)
 {
    GUID TargetC;
    GUID TargetA;
    CoCreateGuid(&TargetC); CoCreateGuid(&TargetA); 
    c1.insert(Mymap::value_type(TargetC,TargetA)); /
    getch();
    return 0;
 }

这是出现的错误: ">c:\program files (x86)\microsoft visual studio 10.0\vc\include\xhash(154): error C2064: term does not evaluate to a function takeing 1 arguments 1> 类未定义“operator()”或用户定义的转换运算符,指向函数指针或函数引用,该函数采用适当数量的参数"

我迫切需要一个解决方案。我会很感激你的意见。谢谢!

最佳答案

std::unordered_map的第三个模板参数是一个哈希函数,第四个模板参数是一个比较函数:

template<class Key,
         class T,
         class Hash = hash<Key>,
         class Pred = std::equal_to<Key>,
         class Alloc = std::allocator<std::pair<const Key, T> > >
class unordered_map;

您正在传递 less_guid 作为第三个模板参数,这听起来像是一个比较函数。

关于c++ - GUID 比较器错误!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6699963/

相关文章:

c++ - 如何将opencv视频发送到ffmpeg

c++ - 冒泡排序程序不输出结果

c++ - 当我想使用 Swig %extend 扩展给定类时 Swig 出现问题

c++ - 在带有转换运算符的初始化程序的情况下,复制列表初始化的假定行为是什么?

visual-c++ - 分发 VC++ Redist... 已安装时运行安装程序会导致问题

c# - 使用 SQLite ADO.Net Provider 需要在不使用参数的情况下将 GUID 直接放入查询的 Where 子句中

c++ - “板”未在此范围内声明

c++ - Visual Studio MFC CListCtrl 复选框 - 空格键

c# - Web Api 2 中的模型 [FromBody] 和 Guid 映射

java - RandomStringUtils.randomAlphanumeric(30) 是有效的 GUID 策略吗?