How can I store an inventory-like list of numbers?

Posted by Rachel on Stack Overflow See other posts from Stack Overflow or by Rachel
Published on 2010-04-29T20:06:11Z Indexed on 2010/04/29 20:17 UTC
Read the original article Hit count: 311

Filed under:
|
|
|

I've got a list of number that I need to keep track of. The numbers are loosely related, but represent distinctly different items. I'd like to keep a list of the numbers but be able to refer to them by name so that I can call them and use them where needed easily. Kind of like an inventory listing, where the numbers all refer to a part ID and I'd like to call them idPart1, idPart2, idPart3 so their purpose is easily identifiable when they are used.

What would be the best way to do this?
1)Define a structure. Say, PartIds. A number of int members will be included, part1, part2 etc. To use, an instance of the structure will be created, values assigned to the members, and the numbers will be used by saying struct.member as needed.
2)Define an enumeration. Use part1, part2 as the enum literals. Store the actual values in a vector or list, each one at the index corresponding to the value of the number's name within the enum. Use the enum literals to retrieve the values, list[enumLit].
3)Something completely different

There's nothing else I need to do with the numbers - just look them up every once in a while. Since there's no processing, I kind of think a new class for them is overkill, but I'm willing to be convinced otherwise.

Any suggestions?

© Stack Overflow or respective owner

Related posts about c++

Related posts about struct