2012-04-03 90 views
3

我想使用模板在圖像中創建區域的排序列表。這裏定義的類在相同的文件中有更多的實現。C++模板中的模板對象

template <typename RegionType> 
class SortedType 
{ 
    public: 
     SortedType(); 
     ~SortedType(); 
     void makeEmpty(); 
     bool isFull() const; 
     int lengthIs() const; 
     void retrieveItem(RegionType&, bool&); 
     void insertItem(RegionType ); 
     void deleteItem(RegionType ); 
     void resetList(); 
     bool isLastItem() const; 
     void getNextItem(RegionType&); 

    private: 
     int length; 
     NodeType<RegionType> *listData; 
     NodeType<RegionType> *currentPos; 
}; 

節點的結構定義是:

template <typename DataType> 
struct NodeType 
{ 
    DataType info; 
    NodeType<DataType> *next; 
}; 

當我嘗試編譯代碼,我得到的錯誤:錯誤:SortedType不上,我原型的功能,使用線式SortedType類。我認爲它與我用於SortedType類的模板有關,NodeType類導致某種問題,但我不知道如何解決它。

編輯 出現的第一個錯誤上是試製的功能:

int computeComponents(ImageType &, ImageType &, SortedType &); 

我在使用該SortedType類的所有函數原型錯誤。 NodeType在SortedType之前聲明。

+2

顯示在您的原型使用SortedType類的函數線;或錯誤的行對應於 – 2012-04-03 00:59:32

+0

看起來很好提供NodeType SortedType之前聲明 – Anycorn 2012-04-03 01:04:23

回答

2
int computeComponents(ImageType &, ImageType &, SortedType &); 

應該

template <typename RegionType> 
int computeComponents(ImageType &, ImageType &, SortedType<RegionType> &); 
+0

我不得不添加模板指定的功能的實現,但一旦我做了,它編譯!非常感謝! – Wenadin 2012-04-03 01:18:01