huhuhu12138 发表于 2018-1-26 14:13:32

这个程序到底哪里出错了啊???

#include<iostream>
#include<math.h>
using namespace std;
class point;
class distance
{
private:
    double length;
public:
    distance(double h);
    void qiuhe(point a,point b);
};
class point
{
private:
    double x;
    double y;
public:
    friend class distance;
    point(double a,double b);
};
int main()
{
    point x1(0,0),x2(0,0);
    distance s(1.0);
    s.qiuhe(x1,x2);
    return 0;
}
point::point(double a,double b)
{
    cin>>a>>b;
    x=a;y=b;
}
distance::distance(double h)
{
    length=h;
    cin>>h;
    length=h;
}
void distance::qiuhe(point a,point b)
{
    distance temp(0.0);
    temp=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    cout<<temp.length;
}

BngThea 发表于 2018-1-26 14:41:15

感觉好乱,你要习惯类用大写字母开头,同类的函数实现放到一起
还有类方法qiuhe中定义类对象是什么鬼

人造人 发表于 2018-1-26 17:55:45

using namespace std;
偷懒可不是什么好事

碰巧std命名空间也有一个叫distance这玩意的

#include<iostream>
#include<math.h>

//using namespace std;
class point;

class distance
{
private:
        double length;
public:
        distance(double h);
        void qiuhe(point a, point b);
};

class point
{
private:
        double x;
        double y;
public:
        friend class distance;
        point(double a, double b);
};

int main()
{
        point x1(0, 0), x2(0, 0);
        distance s(1.0);
        s.qiuhe(x1, x2);
        return 0;
}
point::point(double a, double b)
{
        std::cin >> a >> b;
        x = a; y = b;
}
distance::distance(double h)
{
        length = h;
        std::cin >> h;
        length = h;
}
void distance::qiuhe(point a, point b)
{
        distance temp(0.0);
        temp = sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
        std::cout << temp.length;
}

huhuhu12138 发表于 2018-1-27 09:56:30

人造人 发表于 2018-1-26 17:55
using namespace std;
偷懒可不是什么好事



谢谢,谢谢!!!
页: [1]
查看完整版本: 这个程序到底哪里出错了啊???