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

question on namespace

P: n/a
Is there any difference between:

a) using namespace std;
namespace MyNamespace
{
: // my own code
}

b) namespace MyNamespace
{
using namespace std;
: // my own code
}
I found some of my code do not compile if (b) is used. Why?

Regards,
Milan.
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Milan" <so*****@internet.com> wrote...
Is there any difference between:

a) using namespace std;
namespace MyNamespace
{
: // my own code
}

b) namespace MyNamespace
{
using namespace std;
: // my own code
}
Yes, there is. The latter case brings symbols defined in
'std' namespace into 'MyNamespace'. The former brings them
into the namespace that contains 'MyNamespace', probably the
global one.


I found some of my code do not compile if (b) is used. Why?


Hard to say without seeing your code.

Victor
Jul 19 '05 #2

P: n/a
> b) namespace MyNamespace
{
using namespace std;
: // my own code
}
I found some of my code do not compile if (b) is used. Why?

Because the using directive for std is restrained within the MyNamespace
scope. If you try to access any std entities outside of MyNamespace
as if they were global (i.e. as if you had used a using std at the
top-level scope), then they will fail because the cannot 'see' inside.

-m
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.