1、vector由于空间不足,在push_back后改变了vector的首地址,将导致指针失效。
在实践中需要完成一个类似链表的数据结构:使用了一个容器存储一个现有的结构体,该结构体有两个属性,分别是存储了指向其他结构体的指针的vector。例如:
struct Node
{
string value;
vector<Node*> prev_node;
vector<Node*> next_node;
}
vector<Node> NodeList;
由于无法预知有多少个Node,因此只能由vector自动分配内存,但vector内存不足时的实现原理是占用内存加倍,这个过程会把已有的vector地址改变,因此指向vector的指针会失效,以至于NodeList.push_back()之后会改变vector指向的内容。
由于不是每次都会超出vector预先分配的内存,因此也不是每次push_back都会出现错误,另外改变地址导致指针不知道指到哪里,出现的错误也奇奇怪怪,比如“Error reading variable. Cannot create a lazy string with address”,或者value变成了莫名其妙的东西。在调试中打印了push_back前后的vector的地址,才发现了这个问题。
为了解决这一问题,将vector换成了map,就顺利了很多。
2、vector.size()与负数进行比较,由于vector.size()是unsigned int,在与负数比较时,会把负数自动转换为unsigned int,导致转换为一个非常大的数,造成了条件出错。
https://blog.csdn.net/weixin_41319239/article/details/103226241
3、…/lib/libopenvslam.so:对‘vtable for openvslam::VertexPose’未定义的引用
在设计父类子类继承关系中,经常会出现此类问题。
报错原因:父类中的虚函数只有声明,没有定义。
https://blog.csdn.net/weixin_30480075/article/details/95276136
4、在使用cmake编译matplotlib-cpp项目的时候找不到Python3:
CMake Error at CMakeLists.txt:20 (find_package):
By not providing "FindPython3.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Python3", but
CMake did not find one.
Could not find a package configuration file provided by "Python3" with any
of the following names:
Python3Config.cmake
python3-config.cmake
Add the installation prefix of "Python3" to CMAKE_PREFIX_PATH or set
"Python3_DIR" to a directory containing one of the above files. If
"Python3" provides a separate development package or SDK, be sure it has
been installed.
原因是cmake版本不够,仅3.12以上才支持
参考:https://blog.csdn.net/qq_39332551/article/details/117919981
更新cmake参考:https://blog.csdn.net/qq_27350133/article/details/121994229
cmake 下载地址:https://cmake.org/files/