11
为什么不编译:
可能有一个string
作为返回类型的问题?函数返回constexpr不会编译
constexpr std::string fnc()
{
return std::string("Yaba");
}
为什么不编译:
可能有一个string
作为返回类型的问题?函数返回constexpr不会编译
constexpr std::string fnc()
{
return std::string("Yaba");
}
的std::string
的构造函数的指针char
不constexpr
。在constexpr
函数中,只能使用constexpr
的函数。
谢谢,以前不知道。 – smallB
+1,并且构造函数不能是'constexpr'的原因是它具有无法在编译时执行的副作用(即分配)。 –
但你不觉得这是(这个特别的例子)有点傻吗?字符串常量是const,所以我认为ctor字符串应该是constexpr,以允许将来这样的构造。 – smallB