经典编译错误收集

1.class Carton : public Box
 提示一大堆几十个错误,看来是类出了问题,这其实是全角符号和半角符号的区别的问题,将:改为:即可。
其他还有“与",{}与{}等 。

2.myBox.showVolume;
提示: statement cannot resolve address of overloaded function
这是调用成员函数时忘记加括号,应为myBox.showVolume();
3.#include <iosteam>
 using namespace std;
 cout<< "This is a example." << endl;
提示  iosteam: No such file or directory.
        `cout' undeclared (first use this function) ,
 一个经典的错误,将iostream写错。
4.new types may not be defined in a return type
 two or more data types in declaration of `Draw'
 prototype for `Rectangle Rectangle::Draw()' does not match any in class `Rectangle'
 `Rectangle Rectangle::Draw()' and `virtual void Rectangle::Draw()' cannot be overloaded 
出现四五条错误提示如上,这也是非常常见的错误,原因在于声明了Rectangle类后的}后没有加“;”,然后继续实现 Rectangle::Draw(),


[cpp] view plaincopy
01.class Rectangle : public Shape 
02.{ 
03.    public: 
04.       Rectangle(int len, int width): 
05.                     itsLength(len), itsWidth(width){}; 
06.       virtual ~Rectangle(){} 
07.       virtual long GetArea(){ return itsLength * itsWidth;} 
08.       virtual long GetPerim(){ return 2*itsLength + 2*itsWidth;} 
09.       virtual int GetLength(){ return itsLength;} 
10.       virtual int GetWidth(){ return itsWidth;} 
11.       virtual void Draw(); 
12.    private: 
13.       int itsLength; 
14.       int itsWidth; 
15.}    //此处少一分号“;” 
16.void Rectangle::Draw() 
17.{ 
18.     for(int i=0; i<itsLength; i++) 
19.     { 
20.         for(int j=0; j<itsWidth; j++) 
21.         { 
22.            cout << "*"; 
23.         } 
24.         cout <<"/n"; 
25.     }   
26.     cout << "ok" ; 
27.} 
  
  
5.multiple types in one declaration
此编译错误与上面的第4条类似,也是忘记类声明后忘记加分号,但是在声明的两个类之间  ,中间没有成员函数的实现。  
6.cannot resolve overloaded function `precision' based on conversion to type `std::streamsize '
原语句是 streamsize prec = cout.precision;
这也是非常容易犯的错误,是调用成员函数时没有加(),上面的语句应为
streamsize prec = cout.precision();

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值