There are too many different answers on stack overflow:
- Declare a namespace, and in the hpp file mark all strings as extern const, and in the cpp file put their definitions.
C++ How to share constants with extern between cpp - Error: storage class specified
- Use static const instead of extern const:
- Use an inline function :
static string constants in class vs namespace for constants [c++]
- Use anonymous namespaces!
Where do I put constant strings in C++: static class members or anonymous namespaces?
This is all really confusing. Using an inline function seems like a really lengthy and tedious way to return a string constant.
Why can't we just use namespaces containing static strings, which are defined in the cpp file ?
Can someone please provide an categorical / unequivocal answer of how one should store strings in a constant file, so multiple cpp files can access them ?
Aucun commentaire:
Enregistrer un commentaire