#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的使用
最新推荐文章于 2023-12-22 09:51:50 发布