Implicit Typename Annoyance
I need to make my own iterator class. I'm following guides on the internet and looking at the example set by Josuttis in "The C++ Standard Library." Currently, I'm just playing around trying to get something to work (I'm making an iterator to an array. Talk about desperate.) I would like to use the std::iterator class to help me out. Like this
Code:
template<typename arrType>
class iter : public std::iterator<std::random_access_iterator_tag, arrType>
{
pointer p;
public:
explicit iter(const pointer pz) { p = pz; }
};
When I compile this I get all sorts of warnings about pointer being an implicit typename. So, I have to do this:
Code:
template<typename arrType>
class iter : public std::iterator<std::random_access_iterator_tag, arrType>
{
typename std::iterator<std::random_access_iterator_tag, arrType>::pointer p;
public:
explicit iter(const typename std::iterator<std::random_access_iterator_tag, arrType>::pointer pz) { p = pz; }
};
This looks terrible and it's only going to get worse with more functions! Is there an easier way to get rid of this warning? Thanks.
Re: Implicit Typename Annoyance
Try something like that:
Code:
template<typename arrType>
class iter : public std::iterator<std::random_access_iterator_tag, arrType>
{
private:
typedef typename std::iterator<std::random_access_iterator_tag, arrType> base;
public:
typedef typename base::pointer pointer;
typedef typename base::value_type value_type;
typedef typename base::reference reference;
pointer p;
public:
explicit iter(pointer pz) { p = pz; }
};
If you have defined an array class, the iter class should be
- A nested class of your array class.
- templatized (indirectly) by the type contained in the array, not by the array itself.