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

Question about pointers and vectors



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?

Dec 6 '05 #1
14 1394

"JoeC" <en*****@yahoo.com> wrote in message
news:11*********************@o13g2000cwo.googlegro 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
Dec 6 '05 #2
On 6 Dec 2005 11:40:39 -0800, "JoeC" <en*****@yahoo.com> 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
No**********@Home.com
Dec 6 '05 #3
thanks..

Dec 6 '05 #4
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
Dec 6 '05 #5
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)

Dec 6 '05 #6
"JoeC" <en*****@yahoo.com> 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();
Dec 6 '05 #7
Thanks, I got that but still the push back part is not working it is
saying that ms is not declared.

Dec 6 '05 #8

"JoeC" <en*****@yahoo.com> wrote in message
news:11********************@g47g2000cwa.googlegrou 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

Dec 6 '05 #9
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...
Dec 6 '05 #10
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?

Dec 7 '05 #11
On 7 Dec 2005 09:49:25 -0800, "JoeC" <en*****@yahoo.com> 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::push_back call inside
of your if() scope.

--
Bob Hairgrove
No**********@Home.com
Dec 7 '05 #12
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.

Dec 7 '05 #13

"JoeC" <en*****@yahoo.com> wrote in message
news:11*********************@g44g2000cwa.googlegro 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
Dec 7 '05 #14
Yes, and it was answered or I figureed out what I wanted to do.

Dec 7 '05 #15

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

Similar topics

12
by: BCC | last post by:
If I create a vector of vectors of double: std::vector< std::vector<double> > table1; Are my vectors of doubles uninitialized? Do I have to loop through table1 and initialize each vector of...
2
by: mosfets | last post by:
Hi, I'm having a little trouble figuring out the difference in terms of memory allocation between: class person_info; class A { private:
4
by: Dr. J.K. Becker | last post by:
Hi all, I have vectors that holds pointers to other vectors, like so: vector<whatever> x; vector<whatever*> z; z=&x; Now I add something to x
18
by: Matthias Kaeppler | last post by:
Hi, in my program, I have to sort containers of objects which can be 2000 items big in some cases. Since STL containers are based around copying and since I need to sort these containers quite...
9
by: kathy | last post by:
I am using std::vector in my program: func() { std::vector <CMyClass *> vpMyClass; vpMyClass.push_back(new CMyClass()); vpMyClass.push_back(new CMyClass()); vpMyClass.push_back(new...
8
by: jagguy | last post by:
I am a little confused with the basic concept of vector of pointers. The vector is easy enough. Say you want a vector of pointers to int. The integers are not created outside the vector so all...
73
by: JoeC | last post by:
I am writing a game and I am having a challenge with my combat function. All I want to do is find out how to group pieces that are in the same space. There are two sides and all the units that...
12
by: JoeC | last post by:
I am writing a program and I would like to pass an array of objects to a function and from that object I want to return a valuse to that function how do I do it? Here is what I have: terrain...
1
nabh4u
by: nabh4u | last post by:
Hi, I have a problem referencing to Vectors using pointers i.e. I am not able to use "call by reference" on vector variables. I have a "read()" function in "x.cpp" and "main()" in "y.cpp". I...
160
by: raphfrk | last post by:
Is this valid? int a; void *b; b = (void *)a; // b points to a b += 5*sizeof(*a); // b points to a a = 100;
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.