I am facing an error of expected initializer before noexcept and I'm running this code on windows 10.

I've tried adding braces but of no use I was not able carve out solution to my problem.

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

[Error] expected initializer before 'noexcept' [Error] expected '}' at end of input

1 Answers

2
Superlokkus On

You missed a semicolon after the static vector definition:

#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;
}

Don't forget to always return something out of non void functions

Also don't that you need at least C++11 or higher compatible compilers in order to compile your code.