S
stuie_norris
Hi Group,
I am trying to define a strucutre of constants. Then switch on this
structure of constant values.
In the following example of my problem the code fails to compile due
to:
case (constants.one):
In this statement, "constants.one" is not constant, but occurs in a
context that requires a constant expressio
n.
How should I define a structure of const to switch on.
Thanks
Stuart
#include <stdio>
#include <stdlib>
struct Constant
{
const int one;
const int two;
} constants ={ 65, 66 } ;
int main (int argc, char **argv)
{
char buffer = 'A';
switch (buffer)
{
case (constants.one):
break;
case (constants.two):
break;
}
return 0;
}
I am trying to define a strucutre of constants. Then switch on this
structure of constant values.
In the following example of my problem the code fails to compile due
to:
case (constants.one):
In this statement, "constants.one" is not constant, but occurs in a
context that requires a constant expressio
n.
How should I define a structure of const to switch on.
Thanks
Stuart
#include <stdio>
#include <stdlib>
struct Constant
{
const int one;
const int two;
} constants ={ 65, 66 } ;
int main (int argc, char **argv)
{
char buffer = 'A';
switch (buffer)
{
case (constants.one):
break;
case (constants.two):
break;
}
return 0;
}