#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();
}
this的使用
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.