this指针:指代当前调用的对象
(对象调用函数程序执行的内幕:)
this 大部分情况不需要写,但是必写的情况:
当属性和函数的形式参数同名时,就必须要声明是当前对象的
#include<iostream>
using namespace std;
class point{
public:
void setxy(double x,double y);
private:
double x,y;
};
void point::setxy(double x, double y)
{
this->x=x;
this->y=y;
}
注意:此处的c++写法和java不同,不能用this.x。