![](/img/trans.png)
[英]How can I call my template variadic functor object? I am confused about the parameters and the calling synthax I should use.
[英]How do I use the parameters of the object that I am calling a function on?
//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);
};
是否有一个术语可以代替 OBJECT 来使用函数 Distance 中的 a 值?
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;
}
它甚至是“隐式的”(除非需要(从属名称,与成员同名的本地名称,...))
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.