What effect does static const have on a namespace member
Posted
by user144182
on Stack Overflow
See other posts from Stack Overflow
or by user144182
Published on 2010-05-21T16:31:10Z
Indexed on
2010/05/21
16:40 UTC
Read the original article
Hit count: 269
namespace MyNamespace {
static const double GasConstant = 1.987;
Class MyClass
{
// constructors, methods, etc.
};
};
I previously had GasConstant declared within the MyClass declaration (and had a separate definition in the source file since C++ does not support const
initialization of non-integral types). I however need to access it from other files and also logically it seems like it should reside at the namespace level.
My questions is, what effect does static const
have in this case? Clearly const
means I can't assign a new value to GasConstant, but what does a static member at the namespace mean. Is this similar to filescope static effect, where the member is not accessible outside of the unit?
© Stack Overflow or respective owner