C++中的this是一个指向对象自身的指针。
例子:
例子:
class Test{
int i, j;
public:
void set(int a, int b)
{
this->i = a;//将调用该函数的对象中的成员i 赋值为a
this->j = b;//将调用该函数的对象中的成员j 赋值为b
}
};
int main()
{
Test t;
t.set(10, 20);//这时set函数中的this就是指向t的指针,相当于this=&t;
}