473,498 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Problem with pointers and iterators

On 2008-10-06 16:56:31 -0400, Griff Johns <no@spam.comsaid:
>
MyObjectList::iterator it;
for (it = list.begin(); it != list.end(); ++it) {
// I used to be able to do this:
MyObject* p_obj = it;
Foo(p_obj);

// Or this
Foo(it);

}

But now the error I get is 'cannot convert parameter 1 from
'std::vector<_Ty>::iterator' to 'MyObject *'
Write on the blackboard 100 times: "An iterator is not a pointer."

In VC6 this worked because vector::iterator was a typedef for T*. In
later versions that changed. Both forms satisfy the requirements of the
standard.

Well, you have an iterator that refers to an object, and you need the
address of that object. So there are two steps: get a reference from
the iterator, and take its address.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Oct 6 '08 #1
4 2207
In article <2008100617014316807-pete@versatilecodingcom>,
Pete Becker <pe**@versatilecoding.comwrote:
[deleted]

For those baffled by this slew of messages, the original seems to have
been posted to comp.lang.c++ with followups set to comp.lang.c.
I'm posting this to both with followups set to comp.lang.c++ so
that it can be taken up over there.

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Oct 6 '08 #2
Pete Becker wrote:
On 2008-10-06 16:56:31 -0400, Griff Johns <no@spam.comsaid:
>>
MyObjectList::iterator it;
[...]

Write on the blackboard 100 times: "An iterator is not a pointer."
[...]
Write on the blackboard 100 times: "C++ is not C," and then
consider using comp.lang.c++ for C++ discussions.

--
Er*********@sun.com
Oct 6 '08 #3
Eric Sosman wrote:
Pete Becker wrote:
>Griff Johns <no@spam.comsaid:
>>MyObjectList::iterator it;
[...]

Write on the blackboard 100 times: "An iterator is not a pointer."
[...]

Write on the blackboard 100 times: "C++ is not C," and then
consider using comp.lang.c++ for C++ discussions.
At last, a sane answer for c.l.c.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Oct 6 '08 #4
CBFalconer <cb********@yahoo.comwrote:
Eric Sosman wrote:
Pete Becker wrote:
Griff Johns <no@spam.comsaid:

MyObjectList::iterator it;
[...]

Write on the blackboard 100 times: "An iterator is not a pointer."
[...]
Write on the blackboard 100 times: "C++ is not C," and then
consider using comp.lang.c++ for C++ discussions.

At last, a sane answer for c.l.c.
For Nybbas' sake, Chuck, you don't _have_ to turn yourself into a
Looking-Glass Kenny!

Richard
Oct 7 '08 #5

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

Similar topics

11
1738
by: Gianni Mariani | last post by:
I'm looking at templatizing some code that uses pointers and iterators. There are 3 kinds of values for pointers. - Null - Invalid ( the value is ((T*)-1) ) - Valid Null indicates that...
4
21287
by: Leon | last post by:
Hi all. I'm a bit confused about the use of STL iterators and pointers, and I was wondering if maybe you could give me some pointers ;) Is it possible to convert between iterators and pointers...
12
1326
by: Sims | last post by:
Hi, Here is the code that .NET does not seem to like, but as far as i can see it is valid C++ code. Am i wrong? .... // vector headers ....
8
5006
by: He Shiming | last post by:
Hi, I've developed a class that implements an interface definition. It looks like this: class IRecord { public: // define interface methods by pure virtual methods // no member variables }
8
1981
by: babak | last post by:
Hi everyone I have a problem with Iterators and containers in STL that hopefully someone can help me with. This is what I try to do: I have an associative (map) container and I have a...
8
2559
by: Steve Lambert | last post by:
Hi, I'd be grateful if someone could clarify this for me. In the linked list structure my intention is to declare an array of length 3 containing pointers to node eg. Node *Iterators The...
4
455
by: CoreyWhite | last post by:
/* WORKING WITH STRINGS IN C++ IS THE BEST WAY TO LEARN THE LANGUAGE AND TRANSITION FROM C. C++ HAS MANY NEW FEATURES THAT WORK TOGETHER AND WHEN YOU SEE THEM DOING THE IMPOSSIBLE AND MAKING...
5
6595
by: jgscott | last post by:
I've been trawling around for an answer to this question and thought I'd try here. I have a class Graph, which has a std::list<Nodeas a class member. Node it itself a class that makes extensive...
4
1327
by: pandit | last post by:
Hello i dont understand how to Deal with iterator. its little bit confusing ? how they work??
13
1241
by: Javier | last post by:
Hello, I have some cuestions about constness with standard containers and pointers. Supose I have a list of pointers to some class B: std::list< B * list; I have readed that constness in...
0
7125
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,...
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7165
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,...
1
6887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
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...
1
4910
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...
0
3093
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...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
291
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...

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.