gpt4 book ai didi

c++ - cpp 映射作为函数参数获取警告信息 "discards qualifiers"

转载 作者:行者123 更新时间:2023-11-28 07:12:14 25 4
gpt4 key购买 nike

使用 CPP map ,从 eclipse 编辑器获取警告信息。

Point find_shortest_node(const vector<Point> &openset,const   map<Point, int> &f_score,const map<Point, vector<int> > &f_direction) {

vector<Point>::iterator iner_iterator = openset.begin();
Point min_point = *iner_iterator;
while (iner_iterator != openset.end()) {
if (f_score[*iner_iterator] < f_score[min_point]) {
min_point = *iner_iterator;
}
else if (f_score[*iner_iterator] == f_score[min_point]) {
vector<int> temp1 = f_direction[*iner_iterator], temp2 =f_direction[min_point];
if (temp1.size() < temp2.size()) {
min_point = *iner_iterator;
continue;
}
}
iner_iterator++;
}
return min_point;

警告信息:

passing 'const std::map' as 'this' argument of '_Tp& std::map<_Key, _Tp,_Compare, _Alloc>::operator[](const _KT&) [with _KT = Point, _Key = Point, _Tp = int,_Compare = std::less, _Alloc = std::allocator >]'discards qualifiers [-fpermissive]

最佳答案

出于某种原因,Eclipse 认为 f_scoreconst。根据您的声明,它不是 const,所以这看起来像是 Eclipse 编辑器的问题。

如果你有一个 C++11 兼容的编译器,你可以使用 map::at 解决这个问题。而不是方括号 [] 操作符,像这样:

while (iner_iterator != openset.end()) {
if (f_score.at(*iner_iterator) < f_score.at(min_point)) {
min_point = *iner_iterator;
} else if (f_score.at(*iner_iterator) == f_score.at(min_point)) {
vector<int> temp1 = f_direction.at(*iner_iterator), temp2 =f_direction.at(min_point);
if (temp1.size() < temp2.size()) {
min_point = *iner_iterator;
continue;
}
}
iner_iterator++;
}

关于c++ - cpp 映射作为函数参数获取警告信息 "discards qualifiers",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20785871/

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