Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > namespace and global scope

Reply
Thread Tools

namespace and global scope

 
 
Wat
Guest
Posts: n/a
 
      12-29-2004
If a class is not given a namespace, what does this imply?

From inside of the class, if to call global functions, should global scope
:: be used at all?

If global scope :: used, what benefits does it bring?

Thanks in advance!


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      12-29-2004
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.

V
 
Reply With Quote
 
 
 
 
Bob Hairgrove
Guest
Posts: n/a
 
      12-29-2004
On Wed, 29 Dec 2004 11:49:43 -0500, Victor Bazarov
<(E-Mail Removed)> 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:rawText". 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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Having trouble understanding function scope and variable scope Andrew Falanga Javascript 2 11-22-2008 09:23 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 1 10-25-2006 06:50 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 0 10-25-2006 01:04 PM
How do namespace scope and class scope differ? Steven T. Hatton C++ 9 07-19-2005 06:07 PM
Namespace: Is it a scope or a namespace? Anonymous C++ 3 08-18-2003 01:31 PM



Advertisments