In C, the only compile-time constant is a #define. In C++, you can have
typed constants courtesy of const but not in every context. For class-related
constants, you had to resort to enums and they didn't really work properly.
Some compilers allowed you to have in-class constants by allowing
initialisers for certain member data and this has now been standardised.
Static member data of integral type can now have an initialiser specified in the class declaration. This is then available as a compile-time constant for use within the class:
class Data
{
// ...
static const int maxSize = 256;
char buffer[maxSize];
};
If the member is never used in a way that requires storage to be allocated, no definition is required. That means that if the address of the member is used, explicitly or implicitly, then an out-of-class definition is required for the static member but no initialiser is allowed at that point:
const int Data::maxSize; // no initialiser