用户名:  密码:   
您当前的位置:首页 > 程序设计 >  C与C++ > 

遇到的编译错误

上次修改时间: 2017-12-10 22:19:28      来源:网络总结      作者:钢铁长陈
上一页      路径:DSD\Learn\C与C++\小甲鱼C++\      下一页

1. 提示:\BaiduCloud\dos\2.cpp(109) : error C2562: 'main' : 'void' function returning a value
原因: void main(){... return 0;} 主函数main声明为无返回值的void,但里面却有个return 0来返回整数,改为int main()即可

2. 提示:E:\BaiduCloud\dos\2.cpp(353) : error C2371: 'typeIn' : redefinition; different basic types
原因:char typeIn; 这里的typeIn上面已定义为double typeIn,也就是typeIn不能即定义为char又定义为double

3. 揭示1:E:\BaiduCloud\dos\2.cpp(361) : error C2143: syntax error : missing ':' before ';'
 原因1:switch(typeIn){ case 'C': //这里是冒号,而不是分号
   提示2:E:\BaiduCloud\dos\3.cpp(458) : error C2143: syntax error : missing ';' before 'string'
 原因2:std::cout  "进入子类构器...\n"; 这里的少个<<,应改为std::cout <<
  提示3:E:\BaiduCloud\dos\3.cpp(143) : error C2143: syntax error : missing ';' before 'tag::id'
 原因3:Cat::Cat(std::string theName)::Pet(theName)改为Cat::Cat(std::string theName):Pet(theName) //Pet前是单个冒号

4. 提示:E:\BaiduCloud\dos\2.cpp(391) : warning C4518: 'void ' : storage-class or type specifier(s) unexpected here; ignored
原因:void convertTemperature(double tempIn, char typeIn)
  void convertTemperature(int tempIn, char typeIn); //函数的重载时,上面那行末没有分号
5. 提示:E:\BaiduCloud\dos\2.cpp(408) : error C2601: 'convertTemperature' : local function definitions are illegal
原因: 上一个函数的花括号没有成对出现,出错行是函数实现开始行,但上个函数末没有右花括号,即出错行上一行没有结束的花括号

6. 提示:E:\BaiduCloud\dos\2.cpp(530) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)
原因:未知,但把代码提制到C-Free编译通过
解决方法:加上#include <string>就可以在VC6编译通过了,据说是因为这个头文件中定义了string的相关重载函数

7. 提示:E:\BaiduCloud\dos\2.cpp(561) : error C2065: 'reinterpret' : undeclared identifier
原因:std::cout << *intPtr << reinterpret case<unsigned long>(intPtr),函数写错reinterpret case应改为reinterpret_cast,改_和t

8. 提示:E:\BaiduCloud\dos\2.cpp(565) : error C2374: 'i' : redefinition; multiple initialization
原因:上一个for循环括号中用了i,for(int i=0; i<ITEMS; i++) 后面的for循环括号中要用j,例:for(int j=0; j<ITEMS; j++),便在C-Free下行

9. 提示:E:\BaiduCloud\dos\2.cpp(614) : error C2061: syntax error : identifier 'elemType'
原因: template <typename eleType> //这里定义的是eleType,而后面用的是elemtype,所以提示identifier
  void print(elemType *pBegin, elemType *pEnd) //这里是elemtype,所在提示未定义

10. 提示:E:\BaiduCloud\dos\3.cpp(272) : error C2182: 'StoreQuote' : illegal use of type 'void'
原因: void StoreQuote:inputQuote(),这里的类型和方法间中两个冒号,改为void StoreQuote::inputQuote()

11. 提示:E:\BaiduCloud\dos\3.cpp(79) : error C2065: 'endl' : undeclared identifier
原因:std::cout << "x=" << x << "y=" << y << endl;这里所endl要改为std::endl

12. 运行错误提示:3.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Pet::play(void)" (?play@Pet@@UAEXXZ) //unresolved external symbol未解决的/外部的/符号
 原因:已经把基类Pet中的play()设为纯虚函数(抽象方法),例:virtual void play() = 0; 但是又在子类Cat的play()方法里使用了Pet::play();来调用了基类的方法,Pet的play现在已经是纯虚函数了,没有实现的代码,再调用肯定出错
 解决方法:删除所有调用纯虚函数的语句,如:Pet::play(); //原因是设国等0的方法是没定义代码的

****13. 提示:E:\BaiduCloud\dos\4.cpp(124) : error C2143: syntax error : missing ';' before ':'
 4.obj - 102 error(s), 1 warning(s)
解决方法:虽提示有102个错误,实际上只有一个地方出错,方法:先找一些不同的错误,看哪个地方有没有错,先解决能解决的,其它也许也是这些地方导致的。
 最终原因:Company:Company(std::string theName),两个Company中间应是两个冒号,虽提示102个错误,实际上只有一个

13. 提示:E:\BaiduCloud\dos\4.cpp(222) : error C2440: '=' : cannot convert from 'int (__cdecl *)(int,int)' to 'int (__cdecl *)(void)'
 int fun(int x, int y); //定义一个返回值为整形的函数
 int (*p)(); //声明一返回值为整形的指针函数,***这里错了,应该写为int (*p)(int, int),因这个指针要指向的函数有两个int数据类型的形参,不加形参类型在老板vc6下也能编译通过
 p = fun; //把函数赋给函数指针,这句提示上面的错误,但实际这里是没有错的
14. 提示:e:\baiducloud\dos\4.cpp(385) : error C2511: 'TechCompany::TechCompany' : overloaded member function 'void (class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)' not found in 'TechCompany'  //意思大概是TechCompany::TechCompany在TechCompany类里不能发现,即'TechCompany不是TechCompany的成员函数
 原因:类的构造函数名称写错,
  class TechCompany:public Company{
   TeachCompany(std::string theName, std::string product); }  //构造函数名TeachCompany要和类名TechCompany一样,这里多了个a
15. ****根据编译器找不到什么错误的原因,可以多换几个编译器试试,上面的错误用VC6提示不明显,用c-Free提示的一下就找到错误了
16. 编译时无错,运行时提示: libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main 。 原因:Windows项目要使用Windows子系统, 而不是Console, 可以这样设置:
 [Project] --> [Settings] --> 选择"Link"属性页, 在Project Options下面的框中找到/subsystem:console将其改成/subsystem:windows   //要拖动框右边的滚动条才能找到。