473,513 Members | 2,560 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
2 3658
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2041
by: Piotre Ugrumov | last post by:
I'm following your help. I have written the overload of the operator <<. This overload work! :-) But I have some problem with the overload of the operator >>. I have written the overload of this least operator for the class Person, but I don't know how write the overload for a class that derived from the class Person. The overload of << in...
1
3828
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. In fact there are quite a few things that I learned that I did not know before. For example, while I knew that the new and delete operators can be overloaded...
25
2794
by: Steve Richter | last post by:
is it possible to overload the << operator in c# similar to the way it is done in c++ ? MyTable table = new MyTable( ) ; MyTableRow row = new MyTableRow( ) ; row << new MyTableCell( "cell1 text contents" ) ; row << new MyTableCell( "cell2 text contents" ) ; table << row ; thanks,
10
2196
by: shachar | last post by:
hi all. can i OverLoad Operators - such as Exclamation Mark "!" ? how?
3
1700
by: ES Kim | last post by:
iterator classes provide overloaded operators like this in general: template <typename T> class Iterator { Iterator operator++(int); // postfix ++ T& operator*(); }; Iterator<int> i;
5
2404
by: Suman | last post by:
Having had a look at the C++ FAQ, comp.lang.c++ & comp.std.c++ archives and Stroustrup's FAQs (particularly the following: <url:http://www.research.att.com/~bs/bs_faq2.html#overload-dot/>) I am left to wondering why Stroustrup doesn't mention the *_cast<> operators or operator .* in that particular FAQ. Archived discussions have convinced me...
14
2787
by: Jess | last post by:
Hi, I read about operator overloading and have a question regarding "operator->()". If I have two classes like this: struct A{ void f(); }; struct B{
4
1705
by: Bengan | last post by:
Hi! Where can you see if a class has overloaded operator(like +,-) in Microsofts NET class library on the net? They list members, properties, fields and other stuff for a class but no operatoroverloading. It would be nice to know if a class uses overloaded opetors so you know if its the default behavior or not when using these operators....
2
1851
by: xtrigger303 | last post by:
Hi to all, I was reading Mr. Alexandrescu's mojo article and I've a hard time understanding the following. Let's suppose I have: //code struct A {}; struct B : A {};
0
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5704
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5103
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4759
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3255
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
473
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.