tags:

views:

139

answers:

3

Guys if I have class like below:

template<class T>
class X
{
T** myData_;
public:
class iterator : public iterator<random_access_iterator_tag,/*WHAT SHALL I PUT HERE? T OR T** AND WHY?*/>
{
T** itData_;//HERE I'M HAVING THE SAME TYPE AS MAIN CLASS ON WHICH ITERATOR WILL OPERATE
};
};

Questions are in code next to appropriate lines.
Thank you.

A: 

As for the first question, that should be the data type the iterator returns. Presumably T.

As for the second, it depends completely upon what your iterator actually does, which isn't definite or obvious from the information given.

Note that std::iterator doesn't define any operations for you, it only defines some typedefs which you can inherit.

Potatoswatter
Thats exactly what I'm interested in. I know that std::iterator doesn't define anything for me but in order to have those typedefs defined correctly I must know what shall I put as a type.
There is nothing we can do
+1  A: 

As a starting point, your value type should be the type of object your container holds. My guess would be either T or T*, you don't really provide enough information to say. See here for an explanation of what the various parameters mean. The rest can often be left as defaults.

Dennis Zickefoose
I know what the various parameters mean, but as I've said to Potatoswatter I need to know if I should put T or T** there.
There is nothing we can do
As a starting point, your value type should be the type of object your container holds. I hate to repeat myself, but you still haven't provided any clue as to what that type is.
Dennis Zickefoose
@Dennis Zickefoose the type is T*, I thought that's obvious from class declaration I've provided.
There is nothing we can do
Then that is your answer. `std::iterator<random_access_iterator_tag, T*>`
Dennis Zickefoose
A: 

Unless you just really want to learn this stuff, I'd suggest using Boost.Iterator

Noah Roberts
Boost.Iterator doesn't really prevent you from having to learn anything except how to properly handle the various operators. You still have to understand how iterators work before you can properly implement one.
Dennis Zickefoose
Yes I really want to learn this stuff.
There is nothing we can do