"cppsks" <sk*****@hotmail.com> wrote...
[...] My issues is with the definition of "class definition
level" vs "namespace level". Can you categorize the namespace hi's
namespaceStatic as being at the "namespace level"?
#include <iostream>
namespace hi
{
static int namespaceStatic = 1; // allowed to be initialized here
}
The "namespace level" is particularly used to emphasise the necessity to
define the static data members outside of any class. Example:
// global namespace
class Outer {
class Intermediate {
class Inner {
static double value;
};
};
};
// Outer::Intermediate::Inner::value has to be defined somewhere. But
// you're not allowed to define it inside other classes, you need to get
// out of all classes to the namespace:
double Outer::Intermediate::Inner::value = 3.1415926;
// Now, if you do the same thing with the class hierarchy nestled in some
// namespaces,
namespace O {
namespace I {
class Outer {
class Intermediate {
class Inner {
static double value;
};
};
};
// you may define 'value' here
} // namespace I
// or here
} // namespace O
// or here. It does not matter
double O::I::Outer::Intermediate::Inner::value = 3.1415926;
-----------------------------------
HTH
V