Function returning constexpr does not compile

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 17:58:19

问题


Why doesn't this compile:
Could there be a problem with a string as a return type?

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

回答1:


The constructor of std::string that takes a pointer to char is not constexpr. In constexpr functions you can only use functions that are constexpr.



来源:https://stackoverflow.com/questions/7779013/function-returning-constexpr-does-not-compile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!