0

我有以下类声明:

template <typename Key_T, typename Mapped_T, size_t MaxLevel = 5>
class SkipList
{

public:

  class Iterator
  {
    typedef std::pair<Key_T, Mapped_T> ValueType;
    template <typename Key1, typename Obj1, size_t MaxLevel1> friend class SkipList;
    public:
      //Iterator functions

    private:
      //Iterator Data
  };

  SkipList();
  ~SkipList();
  SkipList(const SkipList &);
  SkipList &operator=(const SkipList &);

  std::pair<Iterator, bool> insert(const ValueType &);
  template <typename IT_T>
  void insert(IT_T range_beg, IT_T range_end);

  void erase(Iterator pos);


private:
  //data
};

当我SkipList insert在类定义之外声明函数时

template <typename Key_T, typename Mapped_T, size_t MaxLevel>
typename std::pair<SkipList<Key_T,Mapped_T,MaxLevel>::Iterator, bool>  SkipList<Key_T,Mapped_T,MaxLevel>::insert(const ValueType &input)

出现以下错误:

SkipList.cpp:349:69: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _T1, class _T2> struct std::pair’
SkipList.cpp:349:69: error:   expected a type, got ‘SkipList<Key_T, Mapped_T, MaxLevel>::Iterator’
SkipList.cpp:349:72: error: ‘SkipList’ in namespace ‘std’ does not name a type
SkipList.cpp:349:80: error: expected unqualified-id before ‘&lt;’ token

我的代码有什么问题?

4

1 回答 1

3

你需要typename关键字:

typename std::pair<typename SkipList<Key_T,Mapped_T,MaxLevel>::Iterator, bool>  SkipList<Key_T,Mapped_T,MaxLevel>::insert(const ValueType &input)

否则编译器认为Iterator是类成员。

于 2013-04-20T00:38:37.320 回答