this的使用

#include<iostream>
using namespace std;
class Tclass
{
public:
	int x,y;
	void print()const//一旦初始化就不能改變,以免指向其他對象
	{cout<<"x="<<x<<","<<"y="<<y<<endl;};
};
int main()
{
  Tclass testclass,testclass2;
  testclass.x=100;
  testclass.y=100;
  testclass.print();
  testclass2.x=10;
  testclass2.y=10;
  testclass2.print();
}

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