473,402 Members | 2,072 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,402 software developers and data experts.

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 2192
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
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
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
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
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
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
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
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
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
by: pandit | last post by:
Hello i dont understand how to Deal with iterator. its little bit confusing ? how they work??
13
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
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,...
0
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...
0
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
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...

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.