我正在使用带有 -std=c++11 标志的 gcc。在我的类定义中,我有以下内容:
private:
const int January = 1,
February = 2,
March = 3,
...
在我的实现中,我有一个 switch 语句。
switch (currentMonth)
{
case January:
returnString = "January";
break;
case February:
returnString = "February";
break;
case March:
returnString = "March";
break;
...
这似乎应该有效,因为月份是不变的;但是,gcc 给了我
calendar.cpp:116:12: error: ‘this’ is not a constant expression
在 switch 语句的每种情况下..为什么这是错误的?