C++常引用作爲函數的參數學習筆記

1.常對象定義:使用const關鍵字修飾的對象稱爲常對象定義格式 類名  const 對象名稱(參數列表)
#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
class A{
	private:
		int x;
		int y;
	public:
		A(int x1,int y1):x(x1),y(y1){
		 Print();	
		}
		
		void Print(){
			cout<<x<<"\t"<<y<<endl; 
		}
}; 
int main(int argc, char** argv) {
	A const a(32,45);
	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章