在类transaction的这个成员函数中,我使用了来自另一个cpp程序的"distance"函数,该函数也是类"GPS_DD"的成员。我的代码如下:
double
Transaction::getDistance()
`{ return GPS_DD.distance(tr_src_where, tr_dst_where);}
此函数计算两个位置从源到目的地的距离。
然后我得到错误消息,我不知道应用这个函数。
这是来自类"GPS_DD"的"距离"函数:
double
GPS_DD::distance(GPS_DD& another) {return GeoDataSource_distance(this->latitude, this->longtitude,
another.latitude, another.longtitude, 'M');
}
不管"GeoDataSource_distance"是什么,应该实现什么代码才能应用于"getDistance"函数?
您需要GPS_DD类的实例,或者在静态方法中转换GPS_DD::distance(但不能在静态方法内部使用此方法(。
例如:而不是:
Transaction::getDistance()
{return GPS_DD.distance(tr_src_where, tr_dst_where);}
您需要实例化GPS_DD类,如下所示:
Transaction::getDistance()
{ GPS_DD anInstanceOfGPS_DD;
return anInstanceOfGPS_DD.distance(tr_src_where, tr_dst_where);}
从所涉及的名称中可以清楚地看出,您正在寻找的是
double Transaction::getDistance()
{
return tr_src_where.distance(tr_dst_where);
}
以计算CCD_ 1和CCD_。
在对象上调用方法的正确语法是非常基本的。是时候修改基本面了吗?