>I think map would be better than vector.
A map is better when the index is a string, but in this case it seems that the index is an integer. The only real issue is that the enum and vector have to keep the same order, which could be an annoying maintenance problem that a map handles automatically. Then again, the contiguous memory of a vector could be a deciding factor, as could the fact that a map is a more complicated data structure and there could be performance or footprint issues.

You can create the vector, but you can't have code outside of any function that assigns values to its data. If you want to initialize all the values to 1, you would use std::vector<int> myVector(3, 1). If you want more complex assignment, you'll have to put into a function.

>> make sure you initialize enum
What do you mean?

07-19-2006

Mario F.

What could be considered good norm to do this?

Declare the global on my utils header file and define a init() function where these globals are defined?

Why do you need to have a global vector? Normally, it would be part of a class that does the initialization in the constructor.

07-19-2006

Mario F.

The vector (in fact it will be a few maps) will hold strings. Much like what is provided with a resource file. Some maps will map to enumerators, but the 3 biggest ones will provide the support for a series of random generated item names (ala Diablo II item generation); "brilliant longsword of maiming", "crude helm of Yark", ....

07-19-2006

Daved

Ok. So put it in a class and do the initalization in the constructor. If you still want the data to be global, you can make a global instance of the class.

07-19-2006

Mario F.

Ok... sorry to bother you Daved. I'm having a blond day...

But you mean putting each map inside his own class?
I wouldn't need more than one instance of this class. Or is that you mean the map would be a static member of the class and there wouldn't be any need to create instances to use it?

07-19-2006

whiteflags

I think that you should create your global vector, do the initializing in a function, and then work with that vector throughout the program. You just need a list of stuff right now. Right?

what have you and then actually use the list throughout your game. Of course, you may find out later it's easier to refactor this list into it's own class. Except now that you have done some preliminary work with the list, you can refactor it into a user-defined type that does exactly what you need and you have made zero design presumptions too early.

However because it's just a global vector I wouldnt give it it's own header. Keep everything in the source file for now, you can make header files later for this if you refactor it.

I think that's what Dave wants to say, but even if he didn't, I wanted to make sure that I wrote this down. :)

07-19-2006

Daved

Whether you put each map in its own class, or all of the maps into one class depends on how interrelated they are. If you wouldn't need more than one instance of the class, that's fine. Not all classes need to be used more than once to be effective. The benefit of putting the global data into a class (or classes) is that all the effort of creating, initializing, and maintaining the data is encapsulated into a single object.

In the simple case, if your vector from post #6 was a non-static member of a class called MyVectorManager, and the constructor of that class initialized the vector data, like you tried to do globally, then you could just create a global instance of MyVectorManager and its constructor will automatically do that work for you. If you have lots of these maps and vectors to initialize, you can still follow the same technique.