如何使用调用函数的对象的参数?

Reb*_*kah 0 c++ function

//Function to find the distance between 2 points
TLength CPoint::Distance(const CPoint& point) const
{
    TLength horiz = abs(point.X() - OBJECT.X());
  TLength vert = abs(point.Y() - OBJECT.Y());
  TLength dist = sqrt(pow(horiz,2) + pow(vert,2)); 
  return dist;
};


int main()
{
const CPoint a = CPoint(4,5);
const CPoint b = CPoint(1,1);

a.Distance(b);

};
Run Code Online (Sandbox Code Playgroud)

是否有一个术语可以代替 OBJECT 来使用函数 Distance 中的 a 值?

Jar*_*d42 5

this 是 self 对象上的指针,所以

TLength CPoint::Distance(const CPoint& point) const
{
    TLength horiz = abs(point.X() - this->X());
    TLength vert = abs(point.Y() - this->Y());
    TLength dist = sqrt(pow(horiz, 2) + pow(vert,2)); 
    return dist;
}
Run Code Online (Sandbox Code Playgroud)

它甚至是“隐式的”(除非需要(依赖名称,与成员同名的本地名称,...))

TLength CPoint::Distance(const CPoint& point) const
{
    TLength horiz = abs(point.X() - X());
    TLength vert = abs(point.Y() - Y());
    TLength dist = sqrt(pow(horiz, 2) + pow(vert,2)); 
    return dist;
}
Run Code Online (Sandbox Code Playgroud)