const int VALUES[] = {7,4,2,1,0}; //or int VALUES[] = {7,4,2,1,0};
this statement inside a class definition gives error. Why?
const int VALUES[] = {7,4,2,1,0}; //or int VALUES[] = {7,4,2,1,0};
this statement inside a class definition gives error. Why?
Because they don't belong there. Also, you must make it static to define a constant value in a class at compile time. Then the compiler will allow you to define its values outside the class.
// This bit goes in header file
class asdf {
static const int VALUES[];
};
// This bit should not go in a header file, because it should occur once and only once
const int asdf::VALUES[]={7,4,2,1,0};
// but this compiles and works fine
class asdf {
const int VALUES[5] = {7,4,2,1,0};
};
It's a warning in my compiler, and I'm not sure it actually does what you're expecting.