第6周项目一:改错

来源:互联网 发布:sql去掉重复记录 编辑:程序博客网 时间:2024/06/04 18:11

错误代码:

#include<iostream>#include<stdlib.h>using namespace std;class C{private:  int x; public:  C(int x){this->x = x;}  int getX(){return x;}};int main(){  const C c(5);  cout<<c.getX();  return 0;}

 

错误列表:

改错1:

#include<iostream>#include<stdlib.h>using namespace std;class C{private:   int x;public:   C(int x)  {this->x=x;}   int getX() const {return x;}};int main(){   const C c(5);      cout<<c.getX();      system("PAUSE");        return 0;}

改错2:

 #include<iostream>#include<stdlib.h>using namespace std;class C{private:   int x;public:   C(int x)  {this->x=x;}   int getX()  {return x;}};int main(){    C c(5); cout<<c.getX();        system("PAUSE"); return 0;}


 

运行结果:

原创粉丝点击