473,385 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Implementation of "->"

Hi. Do you know how is "operator->" implemented for STL iterators?

For example:

struct X {
int x;
...
};

std::list<X> l;
std::list<X>::iterator it = l.begin();
it->x = 1; // <-------------
Jul 23 '05 #1
3 1110
nafai3000 wrote:
Hi. Do you know how is "operator->" implemented for STL iterators?
Just look in their source, I am betting that you have the source to
the standard library along with your compiler.

The usual implementation is to return the address of the element the
iterator refers to.
[...]


V
Jul 23 '05 #2
Actually -> is one of the operators you should not overload.

Keep in mind that the statement:
x->y
means
(*x).y

Such that the dot operator is another operator you can not overload.

The three operators you can not overload in C++ are:
:: (scope)
-> (arrow)
.. (dot)

Jul 23 '05 #3
ben
Keep in mind that the statement:
x->y
means
(*x).y
Not always true.
Such that the dot operator is another operator you can not overload.

The three operators you can not overload in C++ are:
:: (scope)
-> (arrow)
. (dot)


-> can be overloaded. They are useful for pointer like objects, such smart
pointers. For example, the auto_ptr class template implements operator ->.
In general, the following statement:

x->y

means (*x).y is x is a true pointer; (*(x.operator->())).y when x is not a
pointer at all.

ben
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: lpe | last post by:
http://www.pycode.com I was kinda suprised when I could not find any good sites with 3rd party modules (other than the Vaults of Parnassus, where you must host files elsewhere), so I decided to...
145
by: Sidney Cadot | last post by:
Hi all, In a discussion with Tak-Shing Chan the question came up whether the as-if rule can cover I/O functions. Basically, he maintains it can, and I think it doesn't. Consider two...
81
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there...
7
by: SunRise | last post by:
Hi I am creating a C Program , to extract only-Printable-characters from a file ( any type of file) and display them. OS: Windows-XP Ple help me to fix the Errors & Warnings and explain...
175
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
21
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered...
0
by: Peter Insley via .NET 247 | last post by:
Hi, have been searching for an answer for this for quite a while,I would be greatfull for any help. We are developing a codebase that of components that we wouldlike to be able to write in MC++ or...
1
by: Phil Sandler | last post by:
Hello all, Thanks in advance for any help with this. I am trying to get sample code to run from Michael Russell's excellent article on removing whitespace:...
43
by: markryde | last post by:
Hello, I saw in some open source projects a use of "!!" in "C" code; for example: in some header file #define event_pending(v) \ (!!(v)->vcpu_info->evtchn_upcall_pending & \...
2
by: Praveen Chandra | last post by:
Hi, I am trying to build a static library, while building the library i am getting the following error: fatal error C1189: #error : "No sstream/strstream implementation" Following is the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.