1
votes

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.

1
Your identifiers are illegal in C++ code: underscore followed by capital letter is reserved.Konrad Rudolph
Perhaps the compiler is confused by the typename in the iterator typedef?Bo Persson
Changing everything to underscore + small letter and no changeMarcinJuraszek
@Marcin Underscore + small letters is actually not much better since those are reserved in the global namespace. Just don’t use underscores at the start of names at all – it makes no sense anyway.Konrad Rudolph
Have you included the <utility> header?David Rodríguez - dribeas

1 Answers

1
votes

The error that’s causing this is that you’re using typename on non-dependent type names:

typedef typename _Skiplist_const_iterator<_Myt> const_iterator;
typedef typename _Skiplist_iterator<_Myt> iterator;

Removing typename and including the header <memory> where std::pair is 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.