By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,413 Members | 1,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,413 IT Pros & Developers. It's quick & easy.

Want to Overload ++ and -- operators for list iterator

P: n/a
Hi All

I want to overload the ++ and - operator for stl list iterator so that
I could do some thing additional in that
As want to set the current node status also

Can some one please post sample code to use this, I would NOT like to
do it by inheriting the iterator class. Rather I would like to keep a
member iterator and wrap the logic around it

Regards

Feb 22 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Ro*********@rbos.com wrote:
Hi All

I want to overload the ++ and - operator for stl list iterator so that
I could do some thing additional in that
As want to set the current node status also

Can some one please post sample code to use this, I would NOT like to
do it by inheriting the iterator class. Rather I would like to keep a
member iterator and wrap the logic around it
Nothing requires iterators to be classes.

There's no provision for "replacing" the existing operators
for these. The only way to do it is to define your own
iterator class.
Feb 22 '07 #2

P: n/a
On 22 Feb, 10:51, Rohit.ME...@rbos.com wrote:
Hi All

I want to overload the ++ and - operator for stl list iterator so that
I could do some thing additional in that
As want to set the current node status also

Can some one please post sample code to use this, I would NOT like to
do it by inheriting the iterator class. Rather I would like to keep a
member iterator and wrap the logic around it
template<class T, class AllocT>
class my_iterator
{
typedef list<T, AllocTlist_t;
public:
typedef typename list_t::value_type value_type;
typedef typename list_t::pointer pointer;
typedef typename list_t::reference reference;
...

my_iterator(base_t & b) : base_(b) {}
my_iterator operator ++ ()
{
++base_;
// do what you want
return *this;
}
bool operator != (my_iterator const & b) const
{
return base_ != b.base_;
}
reference operator * ()
{
return *base_;
}
private:
typedef typename list_t::iterator base_t;
base_t base_;
};

Feb 22 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.