在类中使用自定义排序时编译错误
Compilation Error using Custom Sort inside Class
我正在尝试在类中使用自定义排序, 如sort(arr,arr+n,cust);
在类函数内。 自定义排序如下所示:
bool cust (int a, int b) {
return pos[a]<pos[b];
}
其中pos
是类中的数组。 但它不编译,并给出编译错误
"无效使用非静态成员函数" 如何摆脱编译错误。
我的代码 -> https://pastebin.com/W1zw0A5s
我试过写:
static bool cust (int a, int b) {
/* same code */
}
这没有帮助。
根据 pastebin 链接,此函数是类中的成员函数。您需要将this
指针绑定到它才能使用它:
sort(sa,sa+n, [this](int a, int b){ return this->sufCmp(a,b); } );
相关文章:
- 二叉排序树无法编译
- 编译时未启用intel oneApi CUDA支持
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 编译包含字符串的代码时遇到问题
- std::tuple 可以根据其值在编译时/运行时排序吗?
- 在类中使用自定义排序时编译错误
- 编译时排序的异构元组
- 分区未编译的快速排序
- 编译错误向量排序和联合
- 使用选择算法编译时递归排序
- 合并排序算法编译错误 [帮助]
- 排序向量时运算符重载的编译错误
- 快速编译高效的排序算法(用于JIT编译)
- GCC 编译时对命名空间中的向量进行排序时错误
- 如何在编译时枚举、排序等类
- c++向量排序方法编译失败,返回预期表达式
- 自定义排序比较函数抛出编译错误
- c++在编译时计算和排序向量
- 使用c++ 11可变模板在编译时快速排序
- 对int[2]数组进行排序无法编译