/* (程序頭部註釋開始)
* 程序的版權和版本聲明部分
* Copyright (c) 2011, 煙臺大學計算機學院學生
* All rights reserved.
* 文件名稱: 第六週 任務一
* 作 者: 楊森
* 完成日期: 2012 年 3 月 26 日
* 版 本 號: V1.0
* 對任務及求解方法的描述部分
* 輸入描述:
* 問題描述:
* 程序輸出:
* 程序頭部的註釋結束
①
#include <iostream>
using namespace std;
class C
{
private:
int x;
public:
C(int x){this->x = x;}
int getX(){return x;}
};
void main()
{
C c(5);
cout<<c.getX()<<endl;
system("pause");
}
②
#include <iostream>
using namespace std;
class C
{
private:
int x;
public:
C(int x){this->x = x;}
int getX()const{return x;}
};
void main()
{
const C c(5);
cout<<c.getX()<<endl;
system("pause");
}
小感: get(x) 爲非 const 成員函數,不能通過 C 類找到
C爲常對象,不能調用