Why have appeared: not a constant expression error; Thought for a long time did not want to understand, the younger brother is a beginner,
Hope the great god to help guide the younger brother, thanked first,
#include
#include
using namespace std;
The class test
{
Public:
The test () : a (0) {};
Void switch_test ();
Private:
const int a;
};
Void test: : switch_test ()
{
Int I=0;
The switch (I)
{
Case 1:
Cout<& lt;" Case 1 is * "& lt;
case a:
Cout<& lt;" It is ok for the test "& lt; break;
}
return;
}
CodePudding user response:
Behind the case cannot use variable!CodePudding user response:
Behind the case seems to only write constant expressions,,,CodePudding user response:
Const int a; The a is a variable, but the value of this variable does not change, can be understood as a const variable,Constants can define
12345;
# define CA 12;
Enum a {=89 a1, a2};
CodePudding user response:
Case grammar are behind must be constant expression, and can only be integer constantCodePudding user response:
After a uninitialized, initialization,Direct writing,,
Private:
The static const int a=1;
CodePudding user response:
But this usage is not good, if you are a really=1, then with case 1 repeat, there will be a problem, don't recommend that you write code, in this way