I was wondering if it were a good idea to use an initializer list to define const strings. So in a class that always requires, say, 10 particular strings, not dependent on anything the user has specified, is an initalizer list a good way to define them? Alternatively, one could create a function to return the desired string also. Which method would be preferred, or is there another, better method?
Also, what would one do if 5 of the string were say, foods and 5, say, drinks? How would one go about declaring these constant drink and food names in groups? My idea would be to create a function for both food and drink taking an enum as a parameter, and the function would return the appropriate string.
Thanks.
By the way, by string, I mean std::string or const char*. I don’t care which one…
I think there is no problem in grouping them in one or two lists.
The advantage of using 2 lists instead of 1 is that you can change the type later of one of them if it would be necessary.
You also can use a static function with an enum (type) that returns the correct string, or using two functions.