我想排序我存储在一个向量中的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