6.1 修改編譯錯誤(兩種方法)

/* (程序頭部註釋開始)
* 程序的版權和版本聲明部分
* 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爲常對象,不能調用

發佈了44 篇原創文章 · 獲贊 3 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章