我想排序我存儲在一個向量中的C++中的一些節點。排序向量的指針
bool compare_func(const node* a, const node* b)
{
return a->getPoint()<b->getPoint();
}
其中,getPoint()返回一個浮點數,我想用它來排序我的矢量。
然而,當我運行它:
std::sort(dataSet.begin(), dataSet.end(), compare_func);
我得到:提前
using namespace std;
std::vector<node*> dataSet;
感謝:
error C2662: 'node::getStartPoint' : cannot convert 'this' pointer from 'const node' to 'node &
error C2662: 'node::getStartPoint' : cannot convert 'this' pointer from 'const node' to 'node &'
error C2039: 'sort' : is not a member of 'std'
error C3861: 'sort': identifier not found
我有這個在我的文件的頂部!
更新: 我重載了getPoint函數,並且確實忘記了算法include,[我原以爲我已經將它包含在一點]。
謝謝!
是'getPoint'和任何其他功能,它使用'const'-合格嗎? – Nbr44
您發佈的代碼並不涉及'getStartPoint',因此它可能是錯誤的或不完整的。不管你想調用什麼方法,都需要被const限定。 – Useless