2014-06-08 2 views
1

그래서 헤더 파일이 많은이 지오메트리 프로젝트를 작성해야합니다. 이 프로그램은 편집 할 때 나에게이 실수를합니다 : field 'p' has incomplete type. 문제는 파일이 서로 종속되어 있다고 생각합니다. 이 헤더 파일은 다음과 같습니다필드에 불완전한 유형이 있습니까?


#ifndef POINT_H_INCLUDED 
#define POINT_H_INCLUDED 
#include "Line.h" 
class Point 
{ 
    friend class Line; 
    friend class Vector; 
    double x; 
    double y; 
    double z; 

public: 
    Point(double, double, double); 
    Point(); 
    Point (Line& , Line&); 
    Point& operator=(Point&); 
}; 


#endif // POINT_H_INCLUDED 

#ifndef VECTOR_H_INCLUDED 
#define VECTOR_H_INCLUDED 
#include "Point.h" 
class Point; 
class Vector 
{ 
    friend class Line; 
    friend class Point; 
    double a; 
    double b; 
    double c; 
    public: 
    Vector(double,double,double); 
    Vector(Point&, Point&); 
    Vector(); 
    Vector& operator=(Vector&); 
}; 

#endif // VECTOR_H_INCLUDED 

#ifndef LINE_H_INCLUDED 
#define LINE_H_INCLUDED 
#include "Point.h" 
#include "Vector.h" 

class Line 
{ 
    Point p; 
    Vector v; 
    public: 
    Line(); 
    Line(Point& , Vector&); 
    Line(Point&,Point&); 
}; 


#endif // LINE_H_INCLUDED 

실수는 Point.h 파일에 제공됩니다. 나는 CodeBlocks에서 일하고있다.

+0

빠른 노트 내가 Line에서 'Point * p'로 만들면 작동한다는 것을 알았지 만 그 이유는 무엇이며 어떻게 피할 수 있습니까? – user3719857

+0

실제로 vector.h에 헤더를 포함시킨 후에'class Point; '를 전달하겠습니까? – alediaferia

답변

1

넌 그러므로 순환 종속성를 생성 point.h line.h 반대로 에 포함된다. Point 클래스의 경우 reference에서 Line까지만 사용되므로 헤더 포함을 제외하고 Line 클래스의 전달 선언을 사용할 수 있습니다.

#ifndef POINT_H_INCLUDED 
#define POINT_H_INCLUDED 

//forward declare 
class Line; 
class Vector; 

class Point 
{ 
    friend class Line; 
    friend class Vector; 
    double x; 
    double y; 
    double z; 

public: 
    Point(double, double, double); 
    Point(); 
    Point (Line& , Line&); 
    Point& operator=(Point&); 
}; 


#endif // POINT_H_INCLUDED 
0

포인트 생성자에서 두 줄의 교차점을 계산하는 것은 좋지 않습니다. "Line.h"헤더에 독립 서스펜션 포인트 교차점 (const Line &, const Line &)을 가지고 원형 종속성을 제거하십시오.

관련 문제