From: RB on
Ugh ok, I still have to study namespace a bit, obviously I do not
yet understand the concept.

And on the following I think this is what I meant to do

#ifndef <nSpace>
using namespace nSpace;
#endif



From: Joseph M. Newcomer on
Namespace isolates names so you must use the qualification of the namespace to find the
names. The 'using' directive tells C++ to implicitly search the namespaces when it finds
an unqualified name, but on the whole, I believe that 'using' is a bad practice; I like
the idea of putting an explicit namspace qualifier, e.g.,

namespace Evaluation {
typedef enum {Good, Bad, Indifferent} judgment;
};

Evaluation::judgment Evaluate(...bunch of args)
{
if(...)
return Evaluation::Good;
...etc.
}

The idea is to avoid "namspace clutter' by having too many names which potentially can
conflict; by adding 'using', the compiler then searches those namespaces in some order
(but without looking up the rules, which might say "whatever the compiler writer feels
like") there's no way to know the order, and while the use of the namespace prevents
compiler errors because of conflicting definitions, using masks them.

The use of file-scoped global variables by using anonymous namespaces is one of the
exceptions here; the belief is that this name, as an unqualified name, is supposed to be
unique. The namspace technique handles some subtle issues about C++ constructors.

Actually, if you look in detail at what is going on, the "anonymous" namespace is assigned
a compiler-generated namespace name, so

namespace {
....stuff here
};

is really the same as

namespace <magic-compiler-generated-name> {
.....stuff here
};
using <magic-compiler-generated-name>;

A namespace doesn't change anything except how the compiler uses the names, but for some
C++ language issues, such as constructors, those names really matter (otherwise,
synthesized constructors, for example, will generate multiply-defined symbols at link
time).
joe

On Sun, 6 Jun 2010 22:21:03 -0400, "RB" <NoMail(a)NoSpam> wrote:

>Ugh ok, I still have to study namespace a bit, obviously I do not
>yet understand the concept.
>
>And on the following I think this is what I meant to do
>
>#ifndef <nSpace>
>using namespace nSpace;
>#endif
>
>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm