By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,238 Members | 1,804 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,238 IT Pros & Developers. It's quick & easy.

Global namespace pollution

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a

"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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.