473,659 Members | 3,420 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 3665
Ro*********@rbo s.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...@rbo s.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_t ype value_type;
typedef typename list_t::pointer pointer;
typedef typename list_t::referen ce reference;
...

my_iterator(bas e_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::iterato r 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
2054
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 Person is this: ostream & operator<<(ostream &out, const Persona &p){ out<<p.getNome()<<"...
1
3844
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 for classes, I did not know that that the global new and delete operators can also be overloaded. ...
25
2832
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
2210
by: shachar | last post by:
hi all. can i OverLoad Operators - such as Exclamation Mark "!" ? how?
3
1705
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
2411
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 that .* _cannot_ be overloaded. I have gathered a notion (perhaps incorrectly) that the *_cast<>...
14
2800
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
1708
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. Regards
2
1862
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
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8748
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8628
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7359
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2754
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

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.