 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Gernot Frisch Guest
|
Posted: Wed Feb 09, 2005 2:11 pm Post subject: un - using namespace? |
|
|
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);}
|
|
| Back to top |
|
 |
Karl Heinz Buchegger Guest
|
Posted: Wed Feb 09, 2005 2:52 pm Post subject: Re: un - using namespace? |
|
|
Gernot Frisch wrote:
| Quote: |
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
[email]kbuchegg (AT) gascad (DOT) at[/email]
|
|
| Back to top |
|
 |
Peter Koch Larsen Guest
|
Posted: Wed Feb 09, 2005 3:24 pm Post subject: Re: un - using namespace? |
|
|
"Gernot Frisch" <Me (AT) Privacy (DOT) net> skrev i en meddelelse
news:36ujstF550admU1 (AT) individual (DOT) net...
| Quote: | 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
| Quote: |
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}
|
|
|
| Back to top |
|
 |
Default User Guest
|
Posted: Wed Feb 09, 2005 6:36 pm Post subject: Re: un - using namespace? |
|
|
Peter Koch Larsen wrote:
| Quote: | "Gernot Frisch" <Me (AT) Privacy (DOT) net> skrev i en meddelelse
news:36ujstF550admU1 (AT) individual (DOT) 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
|
|
| Back to top |
|
 |
Julie Guest
|
Posted: Wed Feb 09, 2005 7:35 pm Post subject: Re: un - using namespace? |
|
|
Karl Heinz Buchegger wrote:
| Quote: | 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.
|
|
| Back to top |
|
 |
Jordan Stewart Guest
|
Posted: Thu Feb 10, 2005 12:31 am Post subject: Re: un - using namespace? |
|
|
Gernot Frisch wrote:
| Quote: | 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);}
|
You could consider surrounding the #include directive with another
namespace (if you don't consider that just as bad).
Jordan
|
|
| Back to top |
|
 |
Peter Koch Larsen Guest
|
Posted: Thu Feb 10, 2005 12:37 am Post subject: Re: un - using namespace? |
|
|
"Default User" <defaultuserbr (AT) yahoo (DOT) com> skrev i en meddelelse
news:1107974168.851866.142790 (AT) c13g2000cwb (DOT) googlegroups.com...
| Quote: |
Peter Koch Larsen wrote:
"Gernot Frisch" <Me (AT) Privacy (DOT) net> skrev i en meddelelse
news:36ujstF550admU1 (AT) individual (DOT) 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
I believe stdafx.h is the name automatically used for precompiled headers. I |
do not use it either. There's nothing wrong with modifying it, however. Just
add the often-used headers and enjoy the benefit (if there is one of
having your own headers compiled as quickly as the windows.h-header (and the
stream-headers, if i remember correctly).
Apart from that: if the header is not used, there's certainly no problem
removing it.
/Peter
|
|
| Back to top |
|
 |
James Aguilar Guest
|
Posted: Thu Feb 10, 2005 3:13 am Post subject: Re: un - using namespace? |
|
|
"Julie" <julie (AT) nospam (DOT) com> wrote
| Quote: | 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
|
|
| Back to top |
|
 |
Stefan Strasser Guest
|
Posted: Thu Mar 24, 2005 3:12 am Post subject: Re: un - using namespace? |
|
|
Jordan Stewart schrieb:
| Quote: | 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;
}
};
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|