On Wed, 07 Apr 2004 18:37:55 +0800, Hunter Hou <hy***@lucent.com>
wrote:
Folks,
If a member variable is initialized in class, it must be static and
const. I know this and regard it as a convention. But who knows why
standard define this?
Integral const expressions are a special case - they can be used as
template parameters, array bounds, etc. No other const type has this
special aspect - there's nothing you can do with a const float with a
known compile time value (such as a float literal, 5.0) that you can't
do with one where the value is known only at runtime. So it is
potentially useful for static integral const members of classes to be
integral const expressions, and for this they have to be defined
inside the class definition.
As for static, what is the purpose of a non static const that you
initialize in the class declaration? All instances will have the same
value for that variable, so it may as well be static.
Tom
--
C++ FAQ:
http://www.parashift.com/c++-faq-lite/
C FAQ:
http://www.eskimo.com/~scs/C-faq/top.html