un - using namespace?

G

Gernot Frisch

hi,

for terrible reasons my stdafx.h has:
using namepsace std;
in it. Now, how can I "un-use the namespace in a cpp file, that _must_
include this header?
 
K

Karl Heinz Buchegger

Gernot said:
hi,

for terrible reasons my stdafx.h has:
using namepsace std;
in it. Now, how can I "un-use the namespace in a cpp file, that _must_
include this header?

You can't
That's one reason why using a 'using'-directive is a really
bad idea in a header file.
 
P

Peter Koch Larsen

Gernot Frisch said:
hi,

for terrible reasons my stdafx.h has:
using namepsace std;
in it. Now, how can I "un-use the namespace in a cpp file, that _must_
include this header?
Why not just remove that using directive? You might have to clean-up some
code, but it should not be that difficult and will give cleaner code
afterwards.
An alternative would be to properly qualify the call in the cpp-file.

/Peter
 
D

Default User

Peter said:
Why not just remove that using directive? You might have to clean-up some
code, but it should not be that difficult and will give cleaner code
afterwards.
An alternative would be to properly qualify the call in the cpp-file.

stdafx.h is a implementation header for Visual Studio and maybe other
inplementations, so I wouldn't recommend changing it. However,
searching my VS6.0 files doesn't find a using statement in stdafx.h.

I haven't found it necessary to use this, although it may be required
for MFC or other off-topic stuff. Many people include it reflexively
because certain help files seem to do so. The OP could try taking out
that header and just including the ones actually needed.



Brian
 
J

Julie

Karl said:
You can't
That's one reason why using a 'using'-directive is a really
bad idea in a header file.

and, further, I think that 'using' is just plain bad. Really, it is a band-aid
fix to lazy programmers and code clutter.
 
S

Stefan Strasser

Jordan said:
You could consider surrounding the #include directive with another
namespace (if you don't consider that just as bad).

that doesn't work with a lot of headers because they use global scope
qualifiers:

struct A{
struct A{
::A *a;
}
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,291
Messages
2,571,455
Members
48,132
Latest member
KatlynC08

Latest Threads

Top