Re: Using nested namespaces
Gennaro Prota <gennaro.prota@yahoo.com> wrote:
I don't know if you are trying to be witty. I wouldn't drop the
top-level namespace but why would one want the two further
"subdivisions"?
I sometimes use nested namespaces for things like compile-time game
settings and such. I *could* use constant naming conventions instead,
but the nested namespaces allow for simpler names to be used inside
the namespaces themselves, besides giving a more logical division of
settings via the namespace blocks.
So I could have things like:
// In a file like settings_normal_mode.hh
namespace Settings
{
namespace NormalMode
{
const LevelSettings kLevelSettings[] =
{
...
};
}
}
// In a file like settings_bonus_levels.hh
namespace Settings
{
namespace BonusLevels
{
const LevelSettings kLevelSettings[] =
{
....
};
}
}
Then in the actual code that uses those settings I usually use full
names like "Settings::NormalMode::kLevelSettings[i]" and so on.
As said, it could all be inside the 'Settings' namespace and the
different types of settings distinguished by a naming convention akin
to the inner namespaces, but doing it like that makes some things simpler
(besides allowing, if there really is a need, to pull things from such a
namespace into another, shortening the names).
It's a matter of taste, really.