Category and Constant Storage

Ok, next problem!

I have a class that I'm going to use to store a category. Right now there are seven options, but there is the potential for a whole lot more in the future. So I started off by storing an integer as the private member. I then used static constants to define the numeric values to represent each category, then a set of static constant strings that corresponds to those numbers in case I need their actual names. Finally I set up some static functions to convert between the integer value and the string, and vice versa.

I'm not sure if this is the best way to go about this. For one it makes the categories names and designations unchangeable. I thought that storing them in a file would be a better option, but then i needed a container that is the equivalent of a constant.

I thought of defining a class to contain an int and the associated string. It would be designed so that it can only be initialized with both items. Then provide no functionality to change the contents. So I've basically created my own constant.

Any suggestions on a better way to structure this? Am I going about it the wrong way?
Thanks for the link! I like the idea, but I'm not sure I'm comfortable with the lack of flexibility. I want to be able to quickly add and remove options without having to change large sections of code. The enumeration would require a lot of hard coded switch stamens to make decision trees.

Are there any other built in methods, or am I stuck creating a class that acts as a constant and using a data file to store and initialize the values?
It sounds like using a std::map might be the way to go. Each option is an element of the map. Use the integer as the key, and the string as the value. You can populate the map at run-time as you read the file containing the options.

See http://www.cplusplus.com/reference/map/map/

Although if the integers are always going to be consecutive, starting from 0, then you can simply use a vector of strings.
Thanks MikeyBoy! I like this one a lot too. It looks like I'm going to have to give up half of my requirements if I want to use built in mechanisms. If I use the enumeration I lose flexibility. If I use the map I lose the constant. I'll have to sit down and decide which is more important, or if I want to keep all aspects and create my own class.

Thanks guys, this has been a great learning experience! I'm really impressed with this forum so far, so be sure you'll see me some more LOL. As soon as I'm more comfortable with what I'm doing I'll pop over to the beginner forums and see if I can help out any with the questions there!
Topic archived. No new replies allowed.