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

un - using namespace?

P: n/a
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?

--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

Jul 23 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Gernot Frisch wrote:

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.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #2

P: n/a

"Gernot Frisch" <Me@Privacy.net> skrev i en meddelelse
news:36*************@individual.net...
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
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

Jul 23 '05 #3

P: n/a

Peter Koch Larsen wrote:
"Gernot Frisch" <Me@Privacy.net> skrev i en meddelelse
news:36*************@individual.net...
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.


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

Jul 23 '05 #4

P: n/a
Karl Heinz Buchegger wrote:
Gernot Frisch wrote:
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.


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

P: n/a

"Julie" <ju***@nospam.com> wrote in message
news:oCtOd.29871$xt.24768@fed1read07...
and, further, I think that 'using' is just plain bad. Really, it is a
band-aid fix to lazy programmers and code clutter.


Or for programmers who don't want to waste their time typing redundant
characters. What is the generally accepted idiom for these kinds of things?
OnceAndOnlyOnce: http://www.c2.com/cgi/wiki?OnceAndOnlyOnce. Maybe you
should say, "Three strikes and you 'using,'" that is, you can "use" a
namespace once you use it three or more times, but less than that is lazy.

- JFA1
Jul 23 '05 #6

P: n/a
Jordan Stewart schrieb:
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;
}
};
Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.