第六周任务一

来源:互联网 发布:java hadoop开发 编辑:程序博客网 时间:2024/05/17 06:50
/* (程序头部注释开始)* 程序的版权和版本声明部分* Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved.* 文件名称:                              * 作    者:刘杨                              * 完成日期:2012 年 3 月 26 日* 版 本 号:          * 对任务及求解方法的描述部分* 输入描述: * 问题描述: * 程序输出: * 程序头部的注释结束*/#include <iostream>using namespace std;class C{private:int x;public:C(int a){x=a;}int getX() const {return x;}};void main(){const C c(5);cout<<c.getX ()<<endl;system("pause");}#include <iostream>using namespace std;class C{private:int x;public:C(int a){x=a;}int getX() const {return (this->x);}};void main(){const C c(5);cout<<c.getX ()<<endl;system("pause");}
 
运行结果:

经验积累:如果定义了一个常对象,则只能调用其中的const成员函数,而不能调用非const成员函数。

原创粉丝点击