Hi, I am kind of confused that when I'm using std::iterator as base class for my reverse_iterator I cant use name aliases that I'm inheriting from this base in my reverse_iterator
It worked on Visual Studio but didn't work when I compiled it in cpp.sh
Here is the code (look for commented part)
Hey, this was very important question for me and I got an answer to it on cprogramming forum and I just want to share the answer jsut in case someone ever needs it.
It was answered by kmdv.
You need to specify type with the typename keyword. The reason is that your reverse_iterator is a class template and, what is really important here, its base class depends on a template argument - Iter. This means that when the compiler sees your type definition, it does not know what std::iterator<...> exactly is, because what it is depends on Iter (which is unknown). If you really want to refer to reference, pointer, and other members from std::iterator<...>, you need to qualify it:
typename std::iterator<VERY LONG ARGUMENT LIST>::reference METHOD();
To avoid repeating this extremely long argument list, it would be convenient to add a typedef to the base class before:
1 2 3 4 5 6 7 8 9 10 11 12 13
template <class Iter>
class reverse_iterator<Iter> : public std::iterator<VERY LONG ARGUMENT LIST>
{
private:
typedef std::iterator<VERY LONG ARGUMENT LIST> base_type;
public:
usingtypename base_type::reference;
usingtypename base_type::pointer;
public:
reference METHOD();
};
However, do you really need your own reverse iterator? Just in case you don't know, there is already a reverse iterator adaptor in STL: std::reverse_iterator<Iter>.