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>’

怎么了?

4

1 回答 1

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) { ...

您忘记用 来限定 Iterator 复制构造函数SkipList::Iterator::Iterator,因此它正在寻找一个名为 的 SkipList 成员函数SkipList::Iterator,因此出现错误“无成员函数”。

于 2013-04-20T00:06:13.487 回答