Folks,
Problem Statement - Does C++ allow a (static) const be limited to a class scope, so I can get rid of #defines that pollute entire namespace?
My observation is NO (in the following DIFFERENT examples), and I'd like to find out why and what's the best alternative. VS generates error C2589: 'const' : illegal token on right side of '::'
EXAMPLE1
// a.h
class A {
…
..
static const uint_32 myConst = 1234;
};
//b.cpp
include “a.h”
… B() { uint32_t arr[A::myConst]; // C2589! const : illegal token on right side of '::' }
EXAMPLE 2
// a.h
class A { … .. enum blah { ... myConst = 1234, .. }; };
//b.cpp
include “a.h”
... B() { uint32_t arr[A::myConst]; // C2589! const : illegal token on right side of '::' }