项目一,修改程序

来源:互联网 发布:vs1003怎么连接单片机 编辑:程序博客网 时间:2024/05/16 01:45

/*
* Copyright (c) 2012, 烟台大学计算机学院
* All rights reserved.
* 作    者:庄子豪
* 完成日期:2013 年  4月5日
* 版 本 号:v1.0
*
* 输入描述:
* 问题描述:
* 程序输出:
* 问题分析:
 *算法设计:

错误代码:

#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;}


修改方案一

#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();    return 0;}


修改方案二

#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();    return 0;}


原创粉丝点击