该类未被另一个hpp中的第二类识别

问题描述 投票:0回答:1

在此项目中,该项目由主要和2个cl2点Point2D和Edge组成,在Edge.hpp文件中未将Point Class识别为类型

文件Point2D.hpp

class Point2D
{
    float x;
    float y;
 public:
     Point2D(float,float);
    ~Point2D();
}

文件Point2D.cpp

#include <iostream>
#include "Point2D.hpp"
#include <math.h>
using namespace std;

Point2D::Point2D(float xx, float yy)
{
    x=xx;
    y=yy;
}

文件Edge.hpp

class Edge
{
    Point2D pA;
    Point2D pB;
public:
    Edge(Point2D,Point2D);
    ~Edge();
};

文件Edge.cpp

#include <iostream>
#include "Edge.hpp"
#include <math.h>

Edge::Edge(Point2D paa, Point2D pbb){
     pA.setx(paa.getx())
     pA.sety(paa.getx())
     pB.setx(pbb.getx())
     pA.sety(pbb.getx())

}

main.cpp

#include <iostream>
#include <math.h>
#include "Point2D.hpp"
#include "Edge.hpp"
using namespace std;

....

我看到的错误:

enter image description here

enter image description here

我打赌它与每个文件中的#include标头有关,也许我丢失了某些东西,或者它们有问题...知道吗?我应该在每个文件的顶部包括什么?

此外,如果我添加

#include "Point2D.hpp" 

在Edge.hpp文件中,出现错误:C:... \ Point2D.hpp | 1 |错误:“类Point2D”的重新定义]

c++ oop
1个回答
0
投票

正如@Igor指出的,您需要在#include "Point2D.hpp"中输入Edge.hpp

#include "Point2D.hpp"

class Edge
{
    Point2D pA;
    Point2D pB;
public:
    Edge(Point2D,Point2D);
    ~Edge();
};

所以编译器知道Point2D是什么。

© www.soinside.com 2019 - 2024. All rights reserved.