473,403 Members | 2,183 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,403 software developers and data experts.

Global namespace pollution

An article states: the global namespace be polluted, causing "a namespace
collision."

What does this mean exactly? Thank you very much!

Jul 22 '05 #1
2 7469

"Birt" <bi***@imp.com> wrote in message
news:r5******************@bgtnsc05-news.ops.worldnet.att.net...
An article states: the global namespace be polluted, causing "a namespace
collision."

What does this mean exactly? Thank you very much!


This is OK.

namespace X
{
int g;
}
int g;
int main()
{
g = 0; // no problem
}
This is not.

namespace X
{
int g;
}
int g;
using namespace X; // pollution

int main()
{
g = 0; // which g?
}

In C++ I think the dangers of pollution are overstated, a bit like the real
world.

john
Jul 22 '05 #2

"Birt" <bi***@imp.com> wrote in message
news:r5******************@bgtnsc05-news.ops.worldnet.att.net...
An article states: the global namespace be polluted, causing "a namespace
collision."

What does this mean exactly? Thank you very much!


When you write using namespace X, the names in that namespace are made visible
in the current scope.

Say,
namespace X{
class Y{
};
}
class Y{
};
int main(){
Y y; // OK
}

Next write using namespace X, so class Y gets introduced in the current scope.

namespace X{
class Y{
};
}
using namespace X;
class Y
{
};
int main{
Y y; // Error...Y is ambiguous
}

-Sharad
Jul 22 '05 #3

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

Similar topics

88
by: Tim Tyler | last post by:
PHP puts most of its functions into a big flat global namespace. That leads to short function names - but creates a namespace minefield for programmers. Lots of the functions are legacies from...
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...
12
by: Alex Hunsley | last post by:
There's no really specific questions in this post, but I'm looking for people's thought on the issues within... The two main versions I've encountered for data pseudo-hiding (encapsulation) in...
8
by: newbie | last post by:
Hello, I have questions about global variables in OOP (in general) and Python (in specific). I understand (I think) that global variables are generally not a good idea. However, if there are...
14
by: Jon Rea | last post by:
I am currently cleaning up an application which was origainlly hashed together with speed of coding in mind and therefore contains quite a few "hacky" shortcuts. As part of this "revamping"...
5
by: Will | last post by:
Hi, I'm linking into a library that has a global constant with the same name as one in my application. My references to the constant are being linked to the value in the library instead of the...
5
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global...
18
by: StephQ | last post by:
I'm facing the following problem: I'm using the Gnu Scientific Library (it is a C math library), and in particular random number generation algorithms. Example code is: .... gsl_rng * r; .......
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
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...

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.