无法弄清楚如何修复类型依赖

时间:2013-11-03 13:58:08

标签: c++

我有这个头文件:

//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

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

1 个答案:

答案 0 :(得分:1)

感谢@Matteo的指导,我解决了这个问题 使用this回答我配置了doxygen以显示头文件依赖性 以这种方式找到循环更容易 如果不需要包含,我删除了包含并添加了声明 在spacepoint.hpp的情况下,我有效地将#include <image.hpp>转为class Image;

在: enter image description here 后:
(图表较小,因为spacepoint.hpp不再依赖image.hpp
enter image description here