On Wed, 29 Dec 2004 11:49:43 -0500, Victor Bazarov
<v.********@comAcast.net> wrote:
Wat wrote: If a class is not given a namespace, what does this imply?
What do you mean by "given a namespace"? If it is declared outside of
any namespace, it is declared in the global namespace.
From inside of the class, if to call global functions, should global scope
:: be used at all?
Only to resolve name conflicts or for readability of the code.
If global scope :: used, what benefits does it bring?
The code becomes a bit more readable if nothing else.
It improves *maintainability*, but not necessarily just by improving
readability. It prevents name-lookup in other namespaces which might
not have been visible when the implementation was first written.
For example, I worked on a project once (in OS Windows) which involved
the open source library ungif. ungif (a library implemented in C
language, mostly in Unix/Linux operating systems) has a function
called "DrawText". C doesn't have namespaces. Of course, Windows API
(also written in C) also has a function called "DrawText". Hmmm ...
what did we do?
We changed the source of ungif so that if __cplusplus was defined, we
put "DrawText" into a namespace "ungif::DrawText". Worked out very
nicely...But what if we had tried to put the entire header into a
namespace?
That would also have been a possible solution. But then we have the
problem that someone might have placed a "using namespace ungif;"
somewhere in a file which also called the Win32API function
"DrawText".
You see where I am going to...?
--
Bob Hairgrove
No**********@Home.com