【发布时间】:2023-03-26 20:05:02
【问题描述】:
以下代码在编译期间初始化两个 const 字符串:
class Test
{
public:
static constexpr const char* LOS = "Los ";
static constexpr const char* ANGELES = "Angeles";
};
如何创建另一个常量字符串(const char* 或const std::string)作为两个常量字符串的连接?添加以下行
static constexpr const std::string LOS_ANGELES = std::string(LOS).append(ANGELES);
发出错误:
error: the type ‘const string {aka const std::basic_string<char>}’ of constexpr variable ‘Test::LOS_ANGELES’ is not literal
【问题讨论】:
标签: c++ string c++11 constexpr