Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Question about pointers and vectors

Reply
Thread Tools

Question about pointers and vectors

 
 
JoeC
Guest
Posts: n/a
 
      12-06-2005


vector<Sprite*>box;
++++++++++++++++++++++++++++++++++
tank = new Bitmap(hdc, IDB_IMAGE2, g_hin);
Sprite * ms = new Sprite(tank, rcBounds, BA_BOUNCE);
break;

box.push_back(ms);

+++++++++++++++++++++++++++++++++++++++

for(vector<Sprite*>::iterator itr = box.begin();
itr != box.end(); itr++){
itr->Update();
}

This isn't working how can I do it better?

 
Reply With Quote
 
 
 
 
Andre Kostur
Guest
Posts: n/a
 
      12-06-2005
"JoeC" <(E-Mail Removed)> wrote in news:1133898039.843277.38830
@o13g2000cwo.googlegroups.com:

>
>
> vector<Sprite*>box;
> ++++++++++++++++++++++++++++++++++
> tank = new Bitmap(hdc, IDB_IMAGE2, g_hin);
> Sprite * ms = new Sprite(tank, rcBounds, BA_BOUNCE);
> break;
>
> box.push_back(ms);
>
> +++++++++++++++++++++++++++++++++++++++
>
> for(vector<Sprite*>::iterator itr = box.begin();
> itr != box.end(); itr++){
> itr->Update();
> }
>
> This isn't working how can I do it better?


1st... handy to post what you mean by "This isn't working".

2nd... the type of *itr is Sprite*

So.... (*itr)->Update();
 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      12-06-2005

"JoeC" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
>
>
> vector<Sprite*>box;
> ++++++++++++++++++++++++++++++++++
> tank = new Bitmap(hdc, IDB_IMAGE2, g_hin);
> Sprite * ms = new Sprite(tank, rcBounds, BA_BOUNCE);
> break;
>
> box.push_back(ms);
>
> +++++++++++++++++++++++++++++++++++++++
>
> for(vector<Sprite*>::iterator itr = box.begin();
> itr != box.end(); itr++){
> itr->Update();

-
> }
>
> This isn't working how can I do it better?


(*itr)->Update();

-Mike


 
Reply With Quote
 
Bob Hairgrove
Guest
Posts: n/a
 
      12-06-2005
On 6 Dec 2005 11:40:39 -0800, "JoeC" <(E-Mail Removed)> wrote:

>
>
>vector<Sprite*>box;
>++++++++++++++++++++++++++++++++++
> tank = new Bitmap(hdc, IDB_IMAGE2, g_hin);
> Sprite * ms = new Sprite(tank, rcBounds, BA_BOUNCE);
> break;
>
> box.push_back(ms);
>
>+++++++++++++++++++++++++++++++++++++++
>
> for(vector<Sprite*>::iterator itr = box.begin();
> itr != box.end(); itr++){
> itr->Update();
>}
>
>This isn't working how can I do it better?


WHAT isn't working?? No way to tell from this snippet of incomplete
code.

--
Bob Hairgrove
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      12-06-2005
JoeC wrote:
> vector<Sprite*>box;
> ++++++++++++++++++++++++++++++++++
> tank = new Bitmap(hdc, IDB_IMAGE2, g_hin);
> Sprite * ms = new Sprite(tank, rcBounds, BA_BOUNCE);
> break;
>
> box.push_back(ms);
>
> +++++++++++++++++++++++++++++++++++++++
>
> for(vector<Sprite*>::iterator itr = box.begin();
> itr != box.end(); itr++){
> itr->Update();
> }
>
> This isn't working how can I do it better?
>


FAQ 5.8, I believe, should help to get closer to the solution.

V
 
Reply With Quote
 
JoeC
Guest
Posts: n/a
 
      12-06-2005
thanks..

 
Reply With Quote
 
JoeC
Guest
Posts: n/a
 
      12-06-2005
I got help with now problem. It was pretty basic.

But box.push_back(ms); Is still viving me an error. It says that
ms is not declared.
I have still to look up they syntax of the switch/case part

42 C:\Documents and Settings\Owner.ROOT\My
Documents\C++\EngineII\action.cpp `ms' undeclared (first use this
function)

 
Reply With Quote
 
JoeC
Guest
Posts: n/a
 
      12-06-2005
Thanks, I got that but still the push back part is not working it is
saying that ms is not declared.

 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      12-06-2005

"JoeC" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ps.com...
>I got help with now problem. It was pretty basic.
>
> But box.push_back(ms); Is still viving me an error. It says that
> ms is not declared.
> I have still to look up they syntax of the switch/case part
>
> 42 C:\Documents and Settings\Owner.ROOT\My
> Documents\C++\EngineII\action.cpp `ms' undeclared (first use this
> function)
>


Judging from the indentation in the incomplete code you posted, I suspect
you're inside some kind of loop or switch statement when ms is declared.
Instead of declaring it inside that block, you could declare it before the
block. Or perhaps, instead, you need to move the push_back to immediately
after the line where you declare the ms variable (and create its instance)?
But we can't tell from your sparse example which approach is appropriate.

-Howard



 
Reply With Quote
 
Ben Pope
Guest
Posts: n/a
 
      12-06-2005
JoeC wrote:
>
> vector<Sprite*>box;
> ++++++++++++++++++++++++++++++++++
> tank = new Bitmap(hdc, IDB_IMAGE2, g_hin);
> Sprite * ms = new Sprite(tank, rcBounds, BA_BOUNCE);
> break;
>
> box.push_back(ms);
>
> +++++++++++++++++++++++++++++++++++++++
>
> for(vector<Sprite*>::iterator itr = box.begin();
> itr != box.end(); itr++){
> itr->Update();
> }
>
> This isn't working how can I do it better?


What's Sprite?

Looks like sprite is a pointer, and your iterator is a "pointer" so
you'll need to dereference twice.

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
 
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
c++ primer statement about vectors containing vectors pauldepstein@att.net C++ 3 03-26-2008 06:22 PM
Ruby, SWIG and C++: how to properly wrap vector of vectors of doubles (2D vectors)? Ruby 0 09-14-2005 05:47 PM
Newbie question on vectors of pointers kelvSYC C++ 1 05-17-2005 11:36 PM
A question about vectors and pointers Mark Probert C++ 8 04-13-2005 05:38 PM



Advertisments