GUID比较错误

GUID Comparer error!

本文关键字:错误 比较 GUID      更新时间:2023-10-16

我编写了以下简单函数—一个无序映射,它接受2个GUIDS作为键和值。但是,我认为它们没有定义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.0vcincludexhash(154):错误C2064:术语不计算为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,它听起来像一个比较函数,作为第三个模板参数