|
-
May 3rd, 2006, 01:57 AM
#1
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.
-
May 3rd, 2006, 02:13 AM
#2
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.
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|