Using const int variable in switch statement

c++, c++11, gcc

Solution

Non-static class members aren't constant expressions. Try this:

static constexpr int January = 1;

Problem

I am using gcc with the -std=c++11 flag. In my class definition I have the following: ``` private: const int January = 1, February = 2, March = 3, ... ``` In my implementation I have a switch statement. ``` switch (currentMonth) { case January: returnString = "January"; break; case February: returnString = "February"; break; case March: returnString = "March"; break; ... ``` This seems like it should work since the months are constant; however, gcc gives me ``` calendar.cpp:116:12: error: ‘this’ is not a constant expression ``` on each case of the switch statement..Why is this wrong?

Original source