我无法运行此代码来打印两点之间的距离.我只是个初学者

I cannot run this code to print distance between two points. I am just a beginner

本文关键字:之间 两点 距离 初学者 运行 代码 打印      更新时间:2024-09-22

我写了下面给出的代码来打印两点之间的距离,但它会引发很多错误。据我所知,错误在于";空隙公式(距离o1,距离o2(";和main。但我找不到确切的错误,因为我只是一个初学者。请引导我。

class distance
{
int a, b;
public:
int c, d;
friend void formula(distance, distance);
distance(int a1, int b1)
{
a = a1;
b = b1;
}
};
void formula(distance o1, distance o2)
{
c = o2.a - o1.a;
d = o2.b - o1.b;
cout<<"The distance is "<<sqrt((c*c)+(d*d))<<endl;
}
int main()
{
distance c1(1, 2), c2(3, 4);
formula(c1, c2);
return 0;
} 

函数中没有定义公式c和d。如果你写,这个函数就会知道它们

o1.c = ...
o1.d = ...