求助:书上示例一句编译时出错如何改?
这是自考教材上的有关用友元函数求两点间距离的程序:class Location{
private: float X,Y;
public:
Location(float xi,float yi){X=xi;Y=yi;}
float GetX(){return X;}
float GetY(){return Y;}
friend float distance(Location& a,Location& b);
};
float distance(Location& a,Location& b)
{
float dx=a.X-b.X;
float dy=a.Y-b.Y;
return sqrt(dx*dx+dy*dy);
}
void main(){
Location p1(6,9),p2(9,6);
float d = distance(p1,p2);
// 仅上句编译不能通过,请大虾指点如何修改,谢谢。
cout<<"The distance is:"<<d<<endl;
}