使用CPP映射,从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;
}
警告信息:
传递'const std :: map'作为'_Tp&std :: map :: operator [](const _KT&)['_KT = Point,_Key = Point,_Tp = int,_Compare = std :: less,_Alloc = std :: allocator>]'丢弃限定符[-fpermissive]
最佳答案
由于某种原因,Eclipse认为f_score
是const
。根据您的声明,它不是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映射作为函数参数获取警告信息“丢弃限定符”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20785871/