What is the correct way in C++ to create a global & static table of strings?
By "global", I mean: Useable from any file that includes the header. But not part of some run-time created singelton objcet.
By "static", I mean: As little run time set up possable. Data in read only memory pages. Only 1 instance of data per app.
By "string", I mean: Null terminated array of chars is fine. std::string would be nice, but I don't think it can be done in terms of the above. Correct?
By "table", I mean: I mean an indexable array. So I guess not a table per-se. But I'm flexable on this point. Open to ideas.
By "C++", I mean: C++ not C. (Update: C++98, not C++11)
Use a
std::arrayof string literals. It has no constructor so it will be loaded statically in the.rodatasection like a C array, yet it has a standard C++ library interface. (iterators, size, etc)A.h:
A.cpp:
http://en.cppreference.com/w/cpp/container/array