I want to use a string constant in multiple places in my cpp file. Should I use std::string or char[]?
static const std::string kConstantString = "ConstantStringValue";
static const char kConstantString[] = "ConstantStringValue";
I was told to prefer the latter since it "avoids static allocation". Doesn't the char array also have to be statically allocated?
static const char[]is to avoid the object fingerprint ofstd::string. Are you dealing with such strict limitations?std::stringyou carry an extra size attributed to the class.std::stringyou carry an extra burden of 32 bytes which is attributed to the class.`