NOEXCEPT之前需要的初始化程序

时间:2019-05-10 05:56:59

标签: c++

我在noexcept之前遇到预期的初始化程序错误,并且我在Windows 10上运行此代码。

我尝试添加括号,但没有用,我无法解决问题。

const static std::vector<std::pair<StatusCode, std::string> > status_codes()       
  noexcept
{
 const static std::vector<std::pair<StatusCode, std::string> > status_codes = {
    } 
}   

[错误]在'noexcept'之前的预期初始化 [Error]预期在输入末尾为'}'

1 个答案:

答案 0 :(得分:2)

您在静态向量定义之后错过了分号:

#include <vector>
#include <string>

using StatusCode = int;

const static std::vector<std::pair<StatusCode, std::string> > status_codes()
  noexcept
{
 const static std::vector<std::pair<StatusCode, std::string> > status_codes = {
    };
 return status_codes;
}

别忘了总是从非void函数中返回某些内容

也不需要至少使用 C ++ 11 或更高兼容的编译器来编译代码。

相关问题