记录一些c++编译报错的细节:
1 报错:error: ‘isnan’ was not declared in this scope
在cpp文件中添加
#include <math.h> //hxz
using namespace std; //hxz
2 error: reference to ‘map’ is ambiguous
/home/meng/Desktop/yellow/C2planner/src/ptm2ogm_v3/src/ptm2ogm.cpp:323:5: error: reference to ‘map’ is ambiguous
map.header.frame_id=world_frame;
^
/home/meng/Desktop/yellow/C2planner/src/ptm2ogm_v3/src/ptm2ogm.cpp:61:25: note: candidates are: nav_msgs::OccupancyGrid map
nav_msgs::OccupancyGrid map;
^
In file included from /usr/include/c++/5/map:61:0,
from /opt/ros/kinetic/include/ros/console.h:42,
from /opt/ros/kinetic/include/ros/ros.h:40,
from /home/meng/Desktop/yellow/C2planner/src/ptm2ogm_v3/src/ptm2ogm.cpp:1:
/usr/include/c++/5/bits/stl_map.h:96:11: note: template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map
class map
^

这里是与c++的库/usr/include/c++/5/bits/stl_map.h:96:11有冲突
修改自己定义的变量名如下,并在使用位置相应修改:
// nav_msgs::OccupancyGrid map;
nav_msgs::OccupancyGrid map_;
这里需要注意以下:map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据 处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时候,在编程上提供快速通道。
我的cpp中使用如下:
std::map<std::pair<int, int>, std::vector<double>> gridMap;
3 call of overloaded ‘abs(double)’ is ambiguous
/home/xxxxapollo_speed/math.hpp:18:25: error: call of overloaded ‘abs(double)’ is ambiguous
if (std::abs(t1 - t0) <= 1.0e-6)
/home/xxxxxx.cpp:25:39: error: call of overloaded ‘abs(const double&)’ is ambiguous
s_ddot_min_(-std::abs(s_ddot_min)),
修改,在对应头文件添加:
#include <cmath>
本文记录了C++编程中遇到的三个典型错误:1) 'isnan'未声明,解决方法是在cpp文件中引入<math.h>;2) 'map'引用模糊,原因是与C++标准库中的map冲突,可以通过更改自定义变量名避免;3) 'abs'函数调用歧义,解决方式是引入<cmath>头文件。这些错误及其解决方案对于C++初学者来说具有很高的参考价值。

1553

被折叠的 条评论
为什么被折叠?



