I have been trying to use a const as the size of an array inside a class declaration. I know it works if I use a static const, but I am having trouble understanding why exactly. More specifically, why can I use const for some data members in a class, but must specify static const for others, as follows:
class Test
{
public:
static const int size = 10; // 1. Works. Must be static to use it as size of array
const int alpha = 20; // 2. Works, but cannot use as size of an array
const double beta = 10.0; // 3. Works
static const double gamma = 20.0; // 4. does not compile
int table[size]; // Works with size, but not alpha
};
I have read many explanations, but have not found an one (or at least one I understand) specifically for what makes case 1 different from case 4, and why I need to make the const static for the array.
Can anyone shed some light on this?
Edit: I'm using VS 2013 if that makes a difference