gpt4 book ai didi

c++ - 通过->语法c++从指针访问函数

转载 作者:行者123 更新时间:2023-11-28 04:18:43 25 4
gpt4 key购买 nike

<分区>

我在类函数中工作:

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;
}

谢谢。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com