The following code initializes two const strings during compilation time:
class Test
{
public:
static constexpr const char* LOS = "Los ";
static constexpr const char* ANGELES = "Angeles";
};
How to create another constant string (const char*
or const std::string
) as the concatenation of the two constant strings? Adding the following line
static constexpr const std::string LOS_ANGELES = std::string(LOS).append(ANGELES);
emits the error:
error: the type ‘const string {aka const std::basic_string<char>}’ of constexpr variable ‘Test::LOS_ANGELES’ is not literal
Aucun commentaire:
Enregistrer un commentaire