R
raan
Microsoft C++ apparently doesn't permit me to initialize a static
constant with in my class scope. Ok, I think that is previously
discussed here and people have suggested some hacks to circumvent the
issue. That being said, when you try to use that constant as in case
expression things get wild.
Here is my implementation.
/*test.h*/
class test{
public:
static const int i;
};
/*test.cpp*/
const int test::i=0;
/*main.cpp*/
#include "test.h"
#include <iostream>
using namespace std;
int main()
{
int k = 0;
switch(k)
{
case test::i:
cout<<"the case\n";
break;
default:
break;
}
return 0;
}
/*********Error snippet ***********/
error C2051: case expression not constant
warning C4065: switch statement contains 'default' but no 'case' labels
How could I get off with it. Technically this is what C++ suggest and
is ideal, right?
constant with in my class scope. Ok, I think that is previously
discussed here and people have suggested some hacks to circumvent the
issue. That being said, when you try to use that constant as in case
expression things get wild.
Here is my implementation.
/*test.h*/
class test{
public:
static const int i;
};
/*test.cpp*/
const int test::i=0;
/*main.cpp*/
#include "test.h"
#include <iostream>
using namespace std;
int main()
{
int k = 0;
switch(k)
{
case test::i:
cout<<"the case\n";
break;
default:
break;
}
return 0;
}
/*********Error snippet ***********/
error C2051: case expression not constant
warning C4065: switch statement contains 'default' but no 'case' labels
How could I get off with it. Technically this is what C++ suggest and
is ideal, right?