错误:必须调用对非静态成员函数的引用
error: reference to non-static member function must be called
编译时,我收到了这个
error: reference to non-static member function must be called
std::sort(sortedCOPG_.begin(),sortedCOPG_.end(),comp_copgNode);
有人能让我做错事吗?我在没有类的情况下尝试了几乎相同的代码,但代码没有问题。这只是在我将代码封装在一个类中之后。为了简单起见,我在这里发布之前删除了很多代码。我试过其他类似的帖子,但都说不通
#include <fstream>
#include <set>
#include <unordered_map>
class Computation {
public:
Computation() {
}
private:
struct copgNode_ {
double weight;
int source;
int target;
};
template <typename Iter>
void mst_score__( Iter first, Iter last) {
Iter current = first;
for (; current != last; ++current) {
for (int i=0; i < n_; ++i) {
if (adjMatrix_[*current][i] != 0 ) sortedCOPG_.push_back(copgNode_{adjMatrix_[*current][i],*current,i});
}
}
//Here, is the line causing errors---
std::sort(sortedCOPG_.begin(),sortedCOPG_.end(),comp_copgNode);
}
void m_init_computation__() {
std::vector<int> mst_test_vec{0,3,7};
mst_score__(mst_test_vec.begin(),mst_test_vec.end());
}
bool comp_copgNode ( const copgNode_& left, const copgNode_& right) {return left.weight < right.weight;}
};
发现错误,必须替换compare函数。因为,它会让排序函数来识别自定义比较器覆盖默认比较器
friend bool operator< ( const copgNode_& left, const copgNode_& right) {return left.weight < right.weight;}
相关文章:
- 如何在C++中使用非静态成员函数作为回调函数
- 静态成员函数使用相同的名称时出现模板类型名称错误
- 在 nullptr 上调用无状态类的非静态成员函数是否合法?
- 为什么传递非静态成员函数会导致编译错误?
- 处理类内的回调时,必须调用对非静态成员函数的引用
- 非静态成员函数的 decltype 格式不正确吗?
- std::异步与非静态成员函数
- C++无效使用非静态成员函数?
- 未使用的C++未优化的静态成员函数/变量
- C++:如何返回指向非静态成员函数的指针?
- 使用静态成员函数而不是普通函数是否有任何开销?
- 在 stream_descriptor::async_wait 中无效使用非静态成员函数
- 为什么我不能像这样在静态成员函数中调用静态成员变量?
- 无法在clang Linux中分配非静态成员函数,但我可以在Visual Studio Windows中分配
- 在类定义中推导内联静态成员函数的返回类型
- `enable_if()`以禁用模板化类的静态成员函数声明
- 错误:无效使用非静态成员函数"int test::hotplug_callback(libusb_contex
- 常量静态成员函数
- 使用 vector.sort() 的非静态成员函数无效使用
- 从静态成员函数访问私有非静态类变量 - C++