0

我有这个头文件:

//region.hpp
#ifndef REGION_HPP
#define REGION_HPP 
...
#include "spacepoint.hpp"

class Image;
//class SpacePoint;

class Region
{
    Rectangle<SpacePoint> boundaries;
...

它给出了这个错误

error: ‘SpacePoint’ was not declared in this scope

当我取消注释时,class SpacePoint我得到了这个:

In instantiation of ‘class Rectangle<SpacePoint>’:
region.hpp:15:27:   required from here
rectangle.hpp:19:7: error: ‘Rectangle<T>::start’ has incomplete type

我试图用一个较小的测试程序重现这个问题,但我不能。
我不知道如何解决这个问题。

4

1 回答 1

1

感谢@Matteo 的指导,我解决了这个问题。
有了这个答案,我配置了 doxygen 来显示头文件的依赖关系。
这样更容易找到循环。
在不需要包含的地方,我删除了包含并添加了一个声明。
spacepoint.hpp我有效转向的情况#include <image.hpp>class Image;

之前: 在此处输入图像描述 之后:(
图表更小,spacepoint.hpp不再依赖image.hpp
在此处输入图像描述

于 2013-11-03T20:29:19.950 回答