欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

不断更新的c++刷题leetcode时常见的错误

最编程 2023-12-31 16:10:12
...

案例1:

我的使用-摘要:

int k = 0;
vector<vector<int>>res;
res[k].push_back(val);

报错:

Line 1037: Char 9: runtime error: reference binding to null pointer of type 'std::vector<int, std::allocator<int>>' (stl_vector.h)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_vector.h:1046:9

根因:vector在还没有分配任何空间时还不能像数组一样用下标形式去访问vector的(v[0]也不行)!!!否则编译通过但报运行错误runtime error!

案例2:

参考:

所有类似runtime error: reference binding to null pointer of type ‘int‘ (stl_vector.h)的报错,都可以来看看-****博客