473,785 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(m s);

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

for(vector<Spri te*>::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 1416

"JoeC" <en*****@yahoo. com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...


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

box.push_back(m s);

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

for(vector<Spri te*>::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(m s);

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

for(vector<Spri te*>::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**********@Ho me.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(m s);

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

for(vector<Spri te*>::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(m s); 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++\E ngineII\action. cpp `ms' undeclared (first use this
function)

Dec 6 '05 #6
"JoeC" <en*****@yahoo. com> wrote in news:1133898039 .843277.38830
@o13g2000cwo.go oglegroups.com:


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

box.push_back(m s);

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

for(vector<Spri te*>::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******** ************@g4 7g2000cwa.googl egroups.com...
I got help with now problem. It was pretty basic.

But box.push_back(m s); 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++\E ngineII\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(m s);

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

for(vector<Spri te*>::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

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

Similar topics

12
2348
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 doubles using new? And in cleaning up, manually delete each of these vectors of doubles? Thanks,
2
2652
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
2024
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
3061
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 frequently, I thought it'd be a better idea to manage additional containers which are initialized with pointers to the objects in the primary containers and sort those (only pointers have to be copied around then). However, that also means if I...
9
2309
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 CMyClass()); //???? Required ??????????????//
8
3616
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 we get is this and it doesn't work vector<int*> ones; ones->push_back(7); //this failed to *ones.push_back(7) ones->push_back(8);
73
4310
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 are in the same space fight. I want to add up the attack factors and defending factors in the same space then figure out the odds so I can roll against an odds table. Basically each piece holds its own x and y loc. Here is what I have right...
12
1623
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 * t; <- an array of different kinds of terrain. This is the line of code: int mod = t->getDef();
1
2456
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 have 3 vector variables in Main(). I want the read function to read the values into the vector using the address I send of the vectors.. Sample code: //x.cpp void read(vector <int> a,vector <int> b,vector < vector <int> > c)
160
5714
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
10325
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.