在问这个之前,我读了previous question,但是问题有点不同。我在课堂上使用它:
static constexpr char* kSuffix = "tos";
[使用c ++ 11用gcc编译时出现此错误:
error: ISO C++ forbids converting a string constant to 'char*' [-Werror=write-strings]
但是constexpr
是比const
严格的约束,因此constexpr
必须是const
,但反之则不然。所以我想知道为什么在这种情况下gcc无法识别constexpr
?
所以
constexpr
必须是const
请注意,constexpr
限定于kSuffix
本身,因此指针变为const
(作为char* const
),但指针不会变成const
(作为const char*
)。 Gcc只是想告诉您,您应该将kSuffix
声明为指向const
的指针,即
static constexpr const char* kSuffix = "tos";