我班级定义中的错误是什么?

时间:2016-04-03 08:51:38

标签: c++ visual-c++

我试图从计算几何图书中获取一些代码,我发现了这个错误 需要帮助!

class Point2D{
        ..
        ..
        some functions
        ..
        ..

        int classify(Point2D &p0, Point2D &p1) {
                Point2D p2 = *this;
                Point2D a = p1 - p0;
                Point2D b = p2 - p0;
                double sa = a.x * b.y - b.x * a.y;

                if (sa > 0.0) return LEFT;
                if (sa < 0.0) return RIGHT;
                if ((a.x * b.x < 0.0) || (a.y * b.y < 0.0)) return BEHIND;
                if (a.length() < b.length()) return BEYOHD;
                if (p0 == p2) return ORIGIN;
                if (p1 == p2) return DESTINATION;
                return BETWEEN;
        }

        int classify(Edge2D ed) {
                return Point2D::classify(ed.org, ed.dest);
        }


};

class Edge2D {
public:
        Point2D org;
        Point2D dest;

        ...bla bla bla

};

编译错误:

syntax error: identifier 'Edge2D'
'ed': undeclared identifier
left of '.org' must have class/struct/union
left of 'dest' must have class/struct union
'Point2D::classify': no overloaded function takes 1 arguments

帮助! :(

1 个答案:

答案 0 :(得分:0)

Edge2D课程之前使用Point2D课程的前瞻声明作为:

class Edge2D;
class Point2D{
    // your class members...
};
class Edge2D{
    // your class members..
};