#include<iostream>
using namespace std;
class eg
{
private:
int a;
public:
eg(int b)
{a=b;}
void add (int m)
{
eg p(5);
p.a=p.a+m;
*this=p;//this指针指向当前对象
}
void display()
{cout<<a<<endl;}
};
int main()
{
eg q(10);
q.display();
q.add(10);
q.display();//15
return 0;
}
this 指向当前对象,通过它可以访问当前对象的所有成员。
最新推荐文章于 2022-11-14 04:00:55 发布