3 Replies - 252 Views - Last Post: 10 December 2012 - 06:30 PM Rate Topic: -----

#1 mshort1803  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-December 12

New to C++ and have a query about arrays

Posted 10 December 2012 - 04:48 PM

Hi Everyone,

I am new to C++ and I have a question regarding arrays.

I know that in C and C++ when you create an array you need to specify how long it needs to be
and then once you've done that it can't change. So my question is, in those RPG games such as World
of Warcraft, how would they have managed inventory?

I have always assumed it would just be an array of items, but the games often have the abbility to
pick up extra bag space etc so how would they handle this if the array size can't change.

Thanks :)

Is This A Good Question/Topic? 0
  • +

Replies To: New to C++ and have a query about arrays

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4018
  • View blog
  • Posts: 12,401
  • Joined: 25-December 09

Re: New to C++ and have a query about arrays

Posted 10 December 2012 - 06:14 PM

There are other containers besides arrays. To name but a few there are list and vector containers that can easily accomplish this requirement.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1072
  • View blog
  • Posts: 4,532
  • Joined: 09-June 09

Re: New to C++ and have a query about arrays

Posted 10 December 2012 - 06:22 PM

Arrays allocated on the stack need to have a known amount of memory at compile time; however, you can allocate a variable about of memory on the run time heap.

std::vector is an example that creates "dynamic memory" on the run time heap, which allows it to expand it's capacity.

This post has been edited by jjl: 10 December 2012 - 06:23 PM

Was This Post Helpful? 0
  • +
  • -

#4 mshort1803  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-December 12

Re: New to C++ and have a query about arrays

Posted 10 December 2012 - 06:30 PM

ahh ok, thanks for that :) I haven't learned about vectors yet
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1