I am not sure that they are completely interchangeable in this particular case. Since you base the size of an array member on a constant, I believe that this should be an enumerated value. I do not have time to search in the standard, but I would be surprised if you could use the int member as the size of the array, even if it is static const , since the actual value may not appear in the header.
// === in myclass.h class MyClass { public: static const int MY_SIZE; private: int ary[MY_SIZE]; }; // === in myclass.cpp /*static*/ const int MyClass::MY_SIZE = 10; // === in otherclass.cpp void OtherClass::operation(MyClass& obj) { std::cout << "Sizeof(MyClass) = " << sizeof(obj) << std::endl; }
I do not think that the compiler can compile otherclass.cpp without compiling myclass.cpp .
In most other cases, I would say Go with the parameter of the static constant of the class, since it will participate a little more reasonably in type inference and the like. I only use enumerated integer constants when I really need to or when they are really enumerated constants (of course).
Edit
I just looked at Standard while I was a goldfinch for lunch (thanks for pushing David).
An integer constant expression can include only literals (2.13), enumerations, const variables or static data elements to initialize integer or enumerated types with constant expressions (8.5), asymmetric integral template parameters, or enumeration types and sizeof expressions.
It seems that the constant and enumeration will work provided that you provide a constant initializer in the declaration (or is it a definition?).
D.Shawley
source share