I’m writing SkipList implementation in a STD-like way: using allocators, iterators, etc. Whole class is done and is working but right now I’m trying to write a header file for the class I made. My current header file content is:
template<class _MySkiplist>
class _Skiplist_const_iterator;
template<class _MySkiplist>
class _Skiplist_iterator;
template<class _Kty,
class _Pr,
class _Alloc>
class skiplist
{
typedef skiplist<_Kty, _Pr, _Alloc> _Myt;
typedef typename _Skiplist_const_iterator<_Myt> const_iterator;
typedef typename _Skiplist_iterator<_Myt> iterator;
typedef typename _Alloc::size_type size_type;
typedef std::pair<iterator, iterator> _Pairii;
typedef std::pair<iterator, bool> _Pairib;
skiplist();
skiplist(const _Alloc& _Al);
skiplist(const _Pr& _Pred);
skiplist(const _Pr& _Pred, const _Alloc& _Al);
~skiplist();
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
size_type size() const;
size_type max_size() const;
bool empty() const;
// _Pairib insert(_Kty& _val);
// _Pairib insert(const _Kty& _val);
size_type erase(const _Kty& x);
void clear();
_Pr key_comp() const;
_Pr value_comp() const;
iterator find(const _Kty& x);
size_type count(const _Kty& x) const;
iterator lower_bound(const _Kty& x) const;
iterator upper_bound(const _Kty& x) const;
// _Pairii equal_range(const _Kty& x) const;
_Alloc get_allocator() const;
};
I’m keeping getting following errors:
Error 1 error C2143: syntax error : missing ‘;’ before ‘<‘
Error 3 error C2238: unexpected token(s) preceding ‘;’
Error 5 error C2238: unexpected token(s) preceding ‘;’
Error 2 error C4430: missing type specifier – int assumed. Note: C++
does not support default-int
All these errors refers to following two lines in header file:
typedef std::pair<iterator, iterator> _Pairii;
typedef std::pair<iterator, bool> _Pairib;
I’m running out of ideas why the errors occur.
The error that’s causing this is that you’re using
typenameon non-dependent type names:Removing
typenameand including the header<memory>wherestd::pairis defined does the trick.Note also that your identifiers are invalid (identifiers starting with underscore followed by either another underscore or a capital letter are reserved) and that you are allowed to use readable identifiers. 😉 The standard library implementations use reserved identifiers to avoid clashes with client code. But you shouldn’t do that.