c++ - 函数返回 constexpr 不编译

标签 c++ compiler-errors c++11 constexpr

为什么不编译:
string 作为返回类型会不会有问题?

constexpr std::string fnc()
{
    return std::string("Yaba");
}

最佳答案

采用指向char 的指针的std::string 的构造函数不是constexpr。在 constexpr 函数中,您只能使用 constexpr 的函数。

关于c++ - 函数返回 constexpr 不编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7779013/

相关文章:

C++ 创建对象数组(来自不同类)

c++ - fstream getline() 未处理的异常

c++ - 错误: no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'List' )

c++ - 为什么我可以从 {} 初始化一个常规数组,而不是一个 std::array

c++ - SFINAE 错误

c++ - 如何检查模板类方法的返回类型?

c++ - 为 UDP 打印出的奇怪字符

c++ - 使用 noexcept C++11 正确实现函数

c++ - 请求非类类型的成员 Class*

c++ - 错误 C2078 : too many initializers