- AddressSanitizer: heap-buffer-overflow on address
堆缓存移除,数组访问越界了。 - C++之invalid initialization of non-const reference of type ‘int&’ from an rvalue of type ‘int’
函数原型上参数是int类型,但是在调用函数的时候却是“int&”(int的地引用类型)。
哪怕函数原型中
bool findNumberIn2DArray(vector<vector>& matrix, int target) ;
参数列表中有vector<vector>& matrix这个&,但是他在这里不是地址引用的意思,只是说这个参数是直接对原对象进行更改,而不是只是拷贝一个副本,传值。
所以主函数中调用时,应是
cout << findNumberIn2DArray(matrix,target);
而不是
cout << findNumberIn2DArray(&matrix,target);
- could not convert ‘s.std::set<_Key, _Compare, _Alloc>::find<int, std::less, std::allocator >(((const key_type)it.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator*<int*, std::vector >()))’ from ‘std::set::iterator {aka std::_Rb_tree_const_iterator}’ to ‘bool’
set<int> s = {1,2};
s
set :: find()函数是预定义的函数,用于检查元素是否属于集合,如果元素在集合容器中找到,则返回指向该元素的迭代器。(所以判定)
- cannot bind ‘std::ostream {aka std::basic_ostream}’ lvalue to ‘std::basic_ostream&&’
原因:直接将vector对象通过cout输出。 vector v = {1,2,3}; cout << v; - 力扣报错:error: non-void function does not return a value in all control paths [-Werror,-Wreturn-type]
原因:not all control paths return a value 这句话的意思是函数并不是所有分支都有返回值。
就是函数中有些else if的分支情况没有返回值,需要增返回值