0

I'm making kind of a funky linked-list based data-structure where every element is associated to a unique heap-allocated internal iterator that points back to it (and external iterators point to those respectively). The idea is to have iterators which aren't invalidated when their element gets removed, but instead find themselves pointing to l.end()

In any case, I'm getting a lot of errors I don't understand. Here's a class that won't compile, but I don't understand why.

template<class T>
class pointer_node {
public:
    pointer_node(const T& t) :
            t(t), p_iter() {
    }
    pointer_node(T&& t) :
            t(move(t)), p_iter() {
    }
private:
    T t;
    std::shared_ptr<const std::list<pointer_node<T>>::iterator> p_iter;
};

The error I get is:

../src/pointer_list.h:28:24: error: ISO C++ forbids declaration of ‘type name’ with no type [-fpermissive] ../src/pointer_list.h:28:60: error: template argument 1 is invalid

Can someone explain this error?

dspyz
  • 5,280
  • 2
  • 25
  • 63

2 Answers2

2

You need a typename keyword: const typename std::list<pointer_node<T>>::iterator.

Without the keyword, the compiler first assumes that iterator is an object, not a type, and it gets confused, perhaps when const is applied to it. The error message could be clearer, though.

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421
2

The type has a dependent name (since it depends on T), which needs explicit name disambiguation:

std::shared_ptr<const typename std::list<pointer_node<T>>::iterator> p_iter;
//                    ^^^^^^^^
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084