473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

namespace and global scope

Wat
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!
Jul 22 '05 #1
2 1929
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
Jul 22 '05 #2
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
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Xavier Decoret | last post by:
The following code does not compoile with gcc-3.2.3 namespace dummy { //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Interface of Foo...
3
by: Anonymous | last post by:
Is namespace the same thing as scope? While reading the book "Thinking in C++", I was under the impression that namespace is, well, a namespace--a feature to create a hiearchy for identifiers...
4
by: Dan Elliott | last post by:
Hello, Converting from a working C program to C++, I run into the following error: I have a header: (header.h) namespace shared{ ... struct X{ ...
2
by: Tony Johansson | last post by:
Hello! I'm reading a book about C++ and there is something that I don't understand so I ask you. Below I have the text from the book and the code from the file where main is located and some...
7
by: Kevin Newman | last post by:
I've been toying with a namespace manager, and wanted to get some input. So what do you think? if (typeof com == 'undefined') var com = {}; if (!com.unFocus) com.unFocus = {}; ...
4
by: Kevin Newman | last post by:
The primary problem I've had with php is the lack of namespaces, which makes OOP very difficult to organize, since you end up with large number of classes cluttering up the same namespace - which...
2
by: Safalra | last post by:
The problem below is obviously some sort of namespace clash, but I don't understand exactly why - can anyone explain? Take the following simple Javascript code: <script type="text/javascript">...
3
by: mackenzie | last post by:
I was wondering why it is "ill-formed if an allocation function is declared in a namespace"? I have done some searching on the web and can not find a reason why; I have stumbled across a few other...
20
by: shapper | last post by:
Hello, How to create a namespace in Javascript containing two methods? And how to access those methods? Thanks, Miguel
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.