自定义结构集声明中出错
Error in custom struct set declaration
我遇到了一个奇怪的编译器错误,因为我刚开始将集合与自定义结构一起使用,所以我不确定到底是什么问题。
我正在尝试创建一组"配对",并使用自定义比较函数插入所述配对。
struct pairT {
std::string first, second;
};
int PairCmp(pairT &one, pairT &two) {
if (one.first < two.first && one.second == two.second) return 0;
else if (one.first < two.first) return -1;
else if (one.first == two.first && one.second < two.second) return -1;
return 1;
}
std::set<pairT> CartesianProduct (std::set<std::string> &one, std::set<std::string> &two) {
std::set<pairT> returnSet(PairCmp);
/.../
我从最后一行代码中得到错误:C2664"无法将参数1从int转换为const std::less…blah,blah,blah。
关于我为什么被踢屁股,有什么建议吗?
使用对象(而不是指针)需要为std::set
命名第二个模板参数,用于比较pairT
的两个对象。有关示例,请参见std::less<>
。
此外,你在这里尝试的似乎是错误的。您试图在CartesianProduct()
中返回一个std::set
,但返回的PairCmp()
返回一个整数。
相关文章:
- GLUT 问题:重新声明 c++ 内置类型'wchar_t'时出错
- 缺少类型说明符 - int 假定 声明静态成员后出错
- 为什么在定义类之前声明类的对象会在友元类中给出错误,而在友元函数中不会出错
- 在 mingw64- 变量下的窗口中编译 openvpn3 时出错,未在范围内声明
- 在循环中重新声明 for 循环变量时出错
- 声明数组>> int arr[] 时出错;在C++(虽然在 Java 中有效)?
- 使用输出在声明容差范围内的EXPECT_NEAR时出错
- GNU 链接器:如果头文件中的指针被声明为 NULL 和/或 extern,则出错
- 在同一命名空间中声明变量和函数是否出错?[C++]
- 在范围内声明时出错
- 在声明类类型的QVector时出错
- "Undefined reference to"使用双模板类声明对象时出错
- 编译向导生成的MFC应用程序时出错;缺少CDocument声明
- 当从c切换到c++时,c++中带有双指针的函数声明和定义会出错
- 尝试在头文件上私下声明向量时出错
- 声明类类型变量时出错
- 'Incomplete type' 为标准::函数声明指向成员的指针函数模板参数时出错
- C++出错:尚未声明object_var
- 编译时类中未声明任何成员函数时出错
- LNK2005在.hpp文件中声明函数时出错