vector question

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2008
Posts: 158
Reputation: cam875 is an unknown quantity at this point 
Solved Threads: 3
cam875 cam875 is offline Offline
Junior Poster

vector question

 
0
  #1
Jul 26th, 2008
Ok, I was wondering if somebody could give me some clarification on a topic that just doesn't seem to make sense to me. I have a class that tells my program all the attributes needed to build another player in my game but there could be 3 players logged in sometimes or 20 players logged in so it needs to be able to dynamically change all the time. I was told that using a vector could solve this problem because you can constantly change its value. But I am having problems understanding it. Would it be like for every player in the game there is another element added to the vector and it uses the sizeof function thing and thats how many objects it needs to instantiate from my class. I just need some further clarification on it. Any help is appreciated. Thanks.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 58
Reputation: ff4930 is an unknown quantity at this point 
Solved Threads: 2
ff4930 ff4930 is offline Offline
Junior Poster in Training

Re: vector question

 
0
  #2
Jul 26th, 2008
You can easily google STL vector information/documentation/library and learn from there.

Here are some basic features.
Vectors are similar to arrays but they are not fixed sizes, they can grow.
When the vector is close to its capacity it will allocate more space automatically.

There are functions to get element by index, get current amount of items in vector and more.

Vectors are templatized meaning it can only store 1 type of objects you can have vectors of ints, or chars, or in your case players but cant be ints and chars.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 401
Reputation: CoolGamer48 is on a distinguished road 
Solved Threads: 40
CoolGamer48's Avatar
CoolGamer48 CoolGamer48 is offline Offline
Posting Pro in Training

Re: vector question

 
0
  #3
Jul 26th, 2008
Depending on your needs, you may also consider lists or deques.

Here's a reference for all STL containers: link
I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC