I am a newbie in c++. I am trying to create a static constant container in c++. In java we typically do that by static constant initialization. For e.g.
class ConstantDefinition {
public static const List<String> stringList = new ArrayList<String>();
static {
stringList.add("foo");
stringList.add("boo");
...blah
}
}
The way java works, I don't need to call a specific method to get the initialization done. Static block gets initialized once the class is loaded into JVM. But in c++ we don't have the same class loading mechanism as java. And what I want is to have a single copy of non modifiable container that I can use without creating the class objects every time. One way I understand is that I create a class(similar to my java example above) and define a const static container. But I am finding it difficult to write that kind of code in C++ because I can't do the initialization without calling a method. So what's the best way to achieve this? The second approach could be that I define a header file and initialize global variables within namespaces. If I take this approach then would it create different global variable each time when I include that header file or the same one will be used?
Thanks, RG