Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Standard Template Library

Author
Message
Mr Squishy
18
Years of Service
User Offline
Joined: 25th Feb 2006
Location:
Posted: 31st Mar 2006 23:06
So im new to STL and i cant quite figure it out. What i have is a class that is called CUnitType and it just holds some basic info like the name and how many hitPoints that particular unit has. So i was thinking that since i dont know how many unitTypes there will be, I could just make a vector of them and add as needed. The problem is that i cant figure out how to access the data in the specific CUnitTypes. I figured it yould be this;


I guess what i am trying to say is:
Any clue on how i can access the members of user defined objects which reside in STL container classes?

Some days the cascading moments which constitute my experience dissolve to reveal a sense of clarity which transcends reasoning.
And then there are days like today.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Apr 2006 18:08
It's this:

int hitPoints = unitTypes[0].hitPoints;

For free Plug-ins and source code http://www.matrix1.demon.co.uk
Mr Squishy
18
Years of Service
User Offline
Joined: 25th Feb 2006
Location:
Posted: 2nd Apr 2006 11:41
Ok, the problem i was having was that i was confused about what exactly an itterator was, but now that i have that cleared up i have annother question:

How do i get the integer representation of an element in a std::vector from an itterator representing that element?

This is what i have now.


This is what i want to do.


Some days the cascading moments which constitute my experience dissolve to reveal a sense of clarity which transcends reasoning.
And then there are days like today.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Apr 2006 16:20
Is there a particular reason you need to use an iterator? Why not stick to using an index in this case?

You can get an offset from a vector iterator, but it's the only container that is allowed to do this in the C++ standard.

Here's the test code I've been using:



For free Plug-ins and source code http://www.matrix1.demon.co.uk
Mr Squishy
18
Years of Service
User Offline
Joined: 25th Feb 2006
Location:
Posted: 3rd Apr 2006 03:59
As to why i needed to; i didnt really i just wanted to know if i could, and i guess to tell you the truth now that i knew about 'em, i guess i just wanted to do something with one.
Now though, it seems like all the referencing, dereferencing, pointer arithmetic and what not that is expressed in those mere 20 characters would sorta be a wasted on a index returner.

Thanks for your help.
Case Closed.

P.S. I totally forgot about the infantry unitType untill you mentioned it.

Keep it simple.
Otherwise, you may not be clever enough.

Login to post a reply

Server time is: 2024-11-19 05:28:17
Your offset time is: 2024-11-19 05:28:17