On compiling, I am receiving this
error: reference to non-static member function must be called
std::sort(sortedCOPG_.begin(),sortedCOPG_.end(),comp_copgNode);
Can someone let me as what I am doing wrong? I tried almost the same code without the classes, but there the code didnt had issues. Its only after I encapsulated the code in a class. I have removed a lot code before posting here, to keep things simple. I tried other similar posts, but couldn't make sense out of it.
#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;}
};
Figured out the bug, had to replace the compare function. As, it would let the sort function to identify that custom comparator overrides the default comparator
friend bool operator< ( const copgNode_& left, const copgNode_& right) {return left.weight < right.weight;}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.