<分区>
我在类函数中工作:
void Planner::CellSort()
{
vector<vector<int>> *pointer_to_open = &openlist;
sort(pointer_to_open->begin(), pointer_to_open->end(), Compare);
}
当我尝试编译它时,出现以下错误:
error: must use '.*' or '->*' to call pointer-to-member function
但是当我尝试以下编译时就好了:
sort((&openlist)->begin(), (&openlist)->end(), Compare);
两者实际上不是在做同样的事情吗?或者这两种方法之间有什么区别。
这是我的比较函数:
bool Planner::Compare(const vector<int> a, const vector<int> b)
{
int f1 = a[2] + a[3]; // f1 = g1 + h1
int f2 = b[2] + b[3]; // f2 = g2 + h2
return f1 > f2;
}
谢谢。