我正在使用gcc和-std = C++ 11标志。在我的班级定义中,我有以下几点:在switch语句中使用const int变量
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;
...
这看起来像它应该工作,因为月是恒定的;然而,海湾合作委员会给我
calendar.cpp:116:12: error: ‘this’ is not a constant expression
对每个case switch语句..为什么这是错误的?
该线在你的例子是'116',它是不是在一个如果分配?或者'switch'本身的情况? – 2013-04-30 22:55:40
我编辑的帖子更清晰 – kennycoc 2013-04-30 22:58:35