本文介绍: int* p;//p是没有对象的野指针*p=3;//对野指针所指区域赋值//malloc函数返回类型是void*,需要强制类型转化一下//只定义到3//但是尝试访问下标为4的地方值得一提的是,现在部分编译器已经将其优化,进而允许用户进行这一危险行为而不会报错,在写代码的时候应该避免访问超出定义的下标nan不存在的数inf/-inf正负无穷大//输出nan//输出-infpublic:int a;cout
我们无论是在学习中还是在工作当中,总是会遇到各种各样的c++编译错误问题,经常会有一种情况就是上一次好像遇到过这种问题,但是就是想不起来了(我就是这样)所以下面这一篇文章就是总结自己遇到的编译以及运行错误。
注意 :
1、造成错误的原因有很多种,错误提示也是多种多样的,我们只需要截取一小部分进行搜索即可。
2、不同的IDE(集成的开发环境,即你写的代码的那个软件)对相同的错误提示不尽相同。
一、错误汇总
1 Arithmetic exception
2 Segmentation fault 或者 Process exited after xxx seconds with return value 一个很大的数(in Dev)
段错误
2.1 调用没有对象的野指针,建议在定义指针的时候new或者malloc一块空间给它(不要直接给指针赋0)
2.2 指针并不是野指针,但是它指向NULL或者指向受系统保护的区域
2.3 下标越界,访问某个数组超出其定义下标的值
2.4 栈溢出
2.5.除零错误(in Dev)
3、输出内容为nan或者inf或者-inf,检查调用函数时是否超出其定义域
4、no match for ‘xxx’ (operand types are ‘xxx’ and ‘xxx’)
4.1 使用系统的类时出错,或者尝试对不正确的类型进行运算符操作
4.2 在使用自己定义的类时,尝试使用系统默认的运算符
5、launch:program “xxx” does not exist 或者 ld returned 1 exit status(in Dev)
6、stray ‘xxx’ in program
7、“xxx” was not declared in this scope
8、redefinition of ‘xxx’ 或者 redeclaration of ‘xxx’
9、expected “xxx” before “xxx”
10、lvalue required as left(或right) operand of assignment
11、cannot bind non-const lvalue reference of type ‘xxx’ to an rvalue of type ‘xxx’
12、assignment of read–only variable ‘xxx’
13、uninitialized const ‘xxx’
14、no matching function for call to ‘func(type)’
15、storage size of ‘xxx’ isn’t known
16、declaration of ‘xxx’ as multidimensional array must have bounds for all dimensions except the first
17、expected primary–expression before ‘xxx’ token
18、size of array ‘xxx’ has non-integral type ‘xxx’
19、invalid types ‘xxx’ for array subscript
20、conflicting declaration ‘xxx’
21、invalid conversion from ‘xxx’ to ‘xxx’ [-fpermissive]
22、‘xxx’ does not name a type
23、cannot convert ‘xxx’ to ‘xxx’
24、lvalue required as unary ‘&’ operand
25、cannot bind non-const lvalue reference of type ‘xxx&’ to an rvalue of type ‘xxx’
26、Unable to start debugging. Program path ‘xxx.exe’is missing or invalid.GDB failed with message:…/Unable to start debugging.Unexpected GDB output from command … :Invalid argument
27、named return values are no longer supported
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。