2013-11-03 24 views
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 

我試圖用較小的測試程序重現問題,但我不能。
我不知道如何去解決這個問題。

+0

做spacepoint。 hpp嘗試包含region.hpp? –

+0

SpacePoint是否偶然在名稱空間中聲明? –

+0

定義了「矩形」的位置? – Jaywalker

回答

1

感謝@ Matteo的指導我解決了這個問題。
With this answer我配置了doxygen來顯示頭文件的依賴關係。
這樣更容易找到循環。
如果include沒有必要,我刪除了include並添加了一個聲明。
spacepoint.hpp的情況下,我轉身有效向#include <image.hpp>class Image;

前: enter image description here 後:
(圖中是spacepoint.hpp小不依賴於image.hpp了)
enter image description here

+1

我更喜歡第二張圖。 – Dialecticus