2013-04-20 52 views
0

我有一个名为SkipList的模板类和一个名为Iterator的嵌套类。类模板中没有成员函数声明

SkipList遵循以下定义:

template <typename Key_T, typename Mapped_T, size_t MaxLevel = 5> 
class SkipList 
{ 
    typedef std::pair<Key_T, Mapped_T> ValueType; 


public: 

    class Iterator 
    { 
     Iterator (const Iterator &); 
     Iterator &operator=(const Iterator &); 
     Iterator &operator++(); 
     Iterator operator++(int); 
     Iterator &operator--(); 
     Iterator operator--(int); 

    private: 
     //some members 
    }; 

Iterator有一个拷贝构造函数,我的定义是这样后声明它的类外:

template <typename Key_T, typename Mapped_T,size_t MaxLevel> 
SkipList<Key_T,Mapped_T,MaxLevel>::Iterator(const SkipList<Key_T,Mapped_T,MaxLevel>::Iterator &that) 

但我得到以下错误:

SkipList.cpp:134:100: error: ISO C++ forbids declaration of ‘Iterator’ with no type [-fpermissive] 
SkipList.cpp:134:100: error: no ‘int SkipList<Key_T, Mapped_T, MaxLevel>::Iterator(const SkipList<Key_T, Mapped_T, MaxLevel>::Iterator&)’ member function declared in class ‘SkipList<Key_T, Mapped_T, MaxLevel>’ 

出了什么问题?

+1

[SSCCE](http://sscce.org)怎么样? – 2013-04-20 00:03:28

+0

@AndyProwl我改变了这个问题 – footy 2013-04-20 00:06:00

回答

3

试试这个:

template <typename Key_T, typename Mapped_T,size_t MaxLevel> 
SkipList<Key_T,Mapped_T,MaxLevel>::Iterator::Iterator 
    (const SkipList<Key_T,Mapped_T,MaxLevel>::Iterator &that) { ... 

您忘记了与SkipList::Iterator::Iterator资格的迭代器拷贝构造函数,所以它正在寻找所谓的SkipList::Iterator一个SkipList成员函数,因此错误“没有成员函数”。

相关问题