Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Problem with pointers and iterators

Reply
Thread Tools

Problem with pointers and iterators

 
 
Griff Johns
Guest
Posts: n/a
 
      10-06-2008
Hi, if I have the following code:
class MyObject
{
public:
MyObject() {};
~MyObject() {};

int x;

}

class MyObjectList : public std::vector<MyObject> {};

void Foo(MyObject* obj)
{
// Do something with obj->x

}

If I loop through it like this:

MyObjectList list;
// stuff list with objects

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 *'

This is after migrating a project from vc6.0 to vc7.1, but I think that
the issue lies with the language standards(?). So why does this happen
now, and how do I resolve it?

Thanks.

 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      10-06-2008
In article <2008100617014316807-pete@versatilecodingcom>,
Pete Becker <(E-Mail Removed)> wrote:
[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.
 
Reply With Quote
 
 
 
 
Default User
Guest
Posts: n/a
 
      10-06-2008
Griff Johns wrote:

Why in the hell did you set follow-ups to comp.lang.c?





Brian
 
Reply With Quote
 
Griff Johns
Guest
Posts: n/a
 
      10-06-2008
What do you mean? I'm posting this to comp.lang.c++ but the only two
replies have gone on about comp.lang.c for some reason.

This is a C++ question and I think this is the right place to post it?

On Mon, 06 Oct 2008 21:59:45 +0000, Default User wrote:
> Griff Johns wrote:
>
> Why in the hell did you set follow-ups to comp.lang.c?
>
>
>
>
>
> Brian


 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      10-06-2008
From: "Default User" <(E-Mail Removed)>
Subject: Re: Problem with pointers and iterators
Date: 6 Oct 2008 22:12:59 GMT
Newsgroups: comp.lang.c
User-Agent: XanaNews/1.17.5.9

Griff Johns wrote:

Don't top-post. Rearranged.

> On Mon, 06 Oct 2008 21:59:45 +0000, Default User wrote:
> > Griff Johns wrote:
> >
> > Why in the hell did you set follow-ups to comp.lang.c?

> What do you mean? I'm posting this to comp.lang.c++ but the only two
> replies have gone on about comp.lang.c for some reason.
>
> This is a C++ question and I think this is the right place to post it?


Here are the full headers from your message:

From: Griff Johns <(E-Mail Removed)>
Subject: Re: Problem with pointers and iterators
Date: Mon, 06 Oct 2008 23:05:36 +0100
Message-ID: <(E-Mail Removed)>
References: <(E-Mail Removed)>
<(E-Mail Removed)>
Lines: 16
Path: uni-berlin.de!fu-berlin.de!news.germany.com!aioe.org!not-for-mail
Newsgroups: comp.lang.c++
Followup-To: comp.lang.c
Organization: Aioe.org NNTP Server
NNTP-Posting-Host: N1FvpErgY0u8uU4+C0wjqA.user.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Complaints-To: http://www.velocityreviews.com/forums/(E-Mail Removed)
User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a
cleansing moment of clarity.)
Xref: uni-berlin.de comp.lang.c++:1031268



You have Followup-To set to another newsgroup, and that's where most of
the replies went.




Brian

 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      10-06-2008
On Oct 6, 1:56*pm, Griff Johns <(E-Mail Removed)> wrote:
> Hi, if I have the following code:
> class MyObject
> {
> public:
> * *MyObject() {};
> * *~MyObject() {};

Delete the semicolons after constructor/destructor.
>
> * *int x;
>
> }
>
> class MyObjectList : public std::vector<MyObject> {};
>
> void Foo(MyObject* obj)
> {
> * *// Do something with obj->x
>
> }
>
> If I loop through it like this:
>
> MyObjectList list;
> // stuff list with objects
>
> 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 *'
>
> This is after migrating a project from vc6.0 to vc7.1, but I think that
> the issue lies with the language standards(?). *So why does this happen
> now, and how do I resolve it?



use Foo(&*it);

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers, pointers, pointers... cerr C Programming 12 04-07-2011 11:17 PM
plain iterators and reverse iterators on vector subramanian100in@yahoo.com, India C++ 10 08-08-2009 08:28 AM
Re: Problem with pointers and iterators CBFalconer C Programming 1 10-07-2008 01:01 PM
Iterators and reverse iterators Marcin Kaliciński C++ 1 05-08-2005 09:58 AM
Problem with pointers and iterators BCC C++ 6 12-01-2004 12:18 AM



Advertisments