c++ - syntax error while returning nested class of a template -
i have following class declaration:
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 };
when declaring skiplist
insert
function outside class definition
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)
the following error comes:
skiplist.cpp:349:69: error: type/value mismatch @ argument 1 in template parameter list ‘template<class _t1, class _t2> struct std::pair’ skiplist.cpp:349:69: error: expected type, got ‘skiplist<key_t, mapped_t, maxlevel>::iterator’ skiplist.cpp:349:72: error: ‘skiplist’ in namespace ‘std’ not name type skiplist.cpp:349:80: error: expected unqualified-id before ‘<’ token
what wrong code?
you need typename
keyword:
typename std::pair<typename skiplist<key_t,mapped_t,maxlevel>::iterator, bool> skiplist<key_t,mapped_t,maxlevel>::insert(const valuetype &input)
or else compiler thinks iterator
class member.
Comments
Post a Comment