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

question on namespace

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
2 1699
"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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Medi Montaseri | last post by:
Hi, Given a collection of similar but not exact entities (or products) Toyota, Ford, Buick, etc; I am contemplating using the Abstraction pattern to provide a common interface to these products....
10
by: da Vinci | last post by:
Hello. First off, I am not sure of the exact jargon used, so I will ask a question regarding it. Then on to my other question. When you use things like cout and cin from the iostream header...
6
by: clinton__bill | last post by:
Hi, I usually use "using namespace <namespace_name>" to reference a namespace. Today I run across a code, in its header file it has this, namespace SP1{ class C1; } While SP1::C1 is a...
11
by: Random | last post by:
I'm confused about the proper use and usefulness of namespaces. I beleive I understand the purpose is so the developer can put classes within namespaces to essentially organize your code. And I...
3
by: CrazyJohn | last post by:
Hi guys, This is my first time posting question here, if I break any rules, please kindly point out. And I'm really glad to be a part of this community. Here is my question, Our lecturer...
10
by: Francois Malgreve | last post by:
Hello everybody, I have a pretty straightforward question regarding namespace. Is there anyone who knows why the following code does not compile on the line Type t =...
54
by: shuisheng | last post by:
Dear All, I am always confused in using constants in multiple files. For global constants, I got some clues from http://msdn.microsoft.com/en-us/library/0d45ty2d(VS.80).aspx So in header...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.