-1

I have this class (declared in the header file):

class HttpError
{
    static std::map<unsigned long, const char *> statusCodes;
    std::string msg;
public:
    HttpError();
};

And I have put this in the corresponding *.cpp file:

HttpError::statusCodes =  {
        {100L, "Continue" },
        {101L, "Switching Protocols" }}

When I compile, I got the error "statusCodes is private within this context". Yes, I know that it is private, but how it is supposed to initialize an static private member??

I've read the answers here and here, and I humbly think I have the same, but surpringsingly does not work. What am I doing wrong?

Raul Luna
  • 1,945
  • 1
  • 17
  • 26

1 Answers1

3

I was forgetting to declare the type of the variable being initialized, that was:

 std::map<unsigned long, const char *>  HttpError::statusCodes =  {
    {100L, "Continue" },
    {101L, "Switching Protocols" }}; 

When I did it, the error was solved.

Raul Luna
  • 1,945
  • 1
  • 17
  • 26