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.

Recommended Answers

All 2 Replies

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.

Depending on your needs, you may also consider lists or deques.

Here's a reference for all STL containers: link

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.