473,587 Members | 2,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1941
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.********@com Acast.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 *maintainabilit y*, 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::DrawTex t". 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**********@Ho me.com
Jul 22 '05 #3

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

Similar topics

2
3509
by: Xavier Decoret | last post by:
The following code does not compoile with gcc-3.2.3 namespace dummy { //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Interface of Foo //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ class Foo { public:
3
6457
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 within the Global Namespace. And that, all identifiers within a given namespace, however deeply nested they are, each of them has the Global Scope. ...
4
7106
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
7501
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 namespace definition with class definitions. The book says "C++ has a global anonymous namespace that is similar to Java's global anonymous...
7
7431
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 = {}; com.unFocus.Namespaces = new function() { this.register = function(namespace) { namespace = namespace.split('.');
4
3077
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 leads to a secondary problem involving php's __autoload feature. Since you cannot specify a namespace when calling a class that may not have been...
2
1754
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"> function scrollLeft(){ alert('scrollLeft') }; function scrollLeft2(){ alert('scrollLeft2') }; scrollLeft(); scrollLeft2(); </script>
3
1849
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 users asking similar questions but there are no definitive replies that I could find. To me a namespace specifies a set of functionality. From an...
20
2274
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
8349
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8221
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6629
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.