c ++中模板中的模板化对象

时间:2012-04-03 00:51:35

标签: c++ templates

我正在尝试使用模板在图像中创建区域的排序列表。这里定义的类在同一个文件中进一步实现。

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之前声明。

1 个答案:

答案 0 :(得分:2)

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

应该是

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