I would like to add to my namespace some string constants, like as follows:
namespace myNamespace
{
//Some string constants.
const string str1 = "str1";
const string str2 = "str2";
...
}
All of these constans are strings up to 20 characters.
Clang-Tidy gives me the following warning: Initialization of str1 with static storage duration may throw an exception that cannot be caught
, and the same warnings for all my string constants. As I understand, this code can be executed before the main() and in case of lack of memory it can cause problems with initialization thses strings.
So, my question is how I should declare string constants in my code? Should I create a class with only these strings as members? Or maybe there is better solution?