2013-04-20 46 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成員函數,因此錯誤「沒有成員函數」。

相關問題