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 に答える