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-07-2005
A Sprite is a pointer, it dosn't matter what else, it is somthing that
moves graphics and the Lib work. The last problem I am having with my
code is that I want to put these sprite pointers in a vector but I get
an error ms is not defined.

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

vector<Sprite*>box;

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

if(num == 6){
ball = new Bitmap(hdc, IDB_IMAGE5, g_hin);
Sprite *ms = new Sprite(ball, rcBounds, BA_BOUNCE);
}

box.push_back(ms); <-- error here.

What am I doing wrong?

 
Reply With Quote
 
 
 
 
Bob Hairgrove
Guest
Posts: n/a
 
      12-07-2005
On 7 Dec 2005 09:49:25 -0800, "JoeC" <(E-Mail Removed)> wrote:

>A Sprite is a pointer, it dosn't matter what else, it is somthing that
>moves graphics and the Lib work. The last problem I am having with my
>code is that I want to put these sprite pointers in a vector but I get
>an error ms is not defined.
>
>109 C:\Documents and Settings\Owner.ROOT\My
>Documents\C++\EngineII\lib.cpp `ms' undeclared (first use this
>function)
>
>vector<Sprite*>box;
>
>++++++++++++++++++++++++++++++++++++++++
>
> if(num == 6){
> ball = new Bitmap(hdc, IDB_IMAGE5, g_hin);
> Sprite *ms = new Sprite(ball, rcBounds, BA_BOUNCE);
> }
>
> box.push_back(ms); <-- error here.
>
>What am I doing wrong?


ms is only valid inside the braces of your if() statement. After the
closing brace, it goes out of scope.

Most likely, you will want to move the vector:ush_back call inside
of your if() scope.

--
Bob Hairgrove
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
JoeC
Guest
Posts: n/a
 
      12-07-2005
Yeh, I realized that I am trying to get this program to run, it
compiles but it is a challenge getting the sprites to show up.

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

"JoeC" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Yeh, I realized that I am trying to get this program to run, it
> compiles but it is a challenge getting the sprites to show up.
>


Do you have a C++ question?

-Howard


 
Reply With Quote
 
JoeC
Guest
Posts: n/a
 
      12-07-2005
Yes, and it was answered or I figureed out what I wanted to do.

 
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