473,395 Members | 1,846 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,395 software developers and data experts.

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);}

Jul 23 '05 #1
6 2923
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

"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

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
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

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

Similar topics

5
by: cppaddict | last post by:
It is typical to put the line: using namespace std; at the top of a file which makes use of std library objects. To take a simple example: #include <iostream> using namespace std;
8
by: Petter Reinholdtsen | last post by:
I ran into a problem on HP-UX 11.00 the other day, where it refused to compile a program using 'using namespace std;' at the top. The reason seem to be that the compiler refuses to accept 'using...
3
by: Pranav Shah | last post by:
What is the differrence between using the "using" caluse outside of the namespace definition and inside the namespace. Example Outside: using System; namespace Example.Outside { }
0
by: Simon | last post by:
I need call a LoginUser API from MC++ dll, but when I try to call the I have always the same exception: "System.NullReferenceException: Object reference not set to an instance of an object. at...
3
by: Brian Gideon | last post by:
I stumbled across something odd today about the placement of the using keyword. Section 9.3.2 of the C# v1.1 specification did not answer my question. My confusion is isolated to what happens in...
8
by: acb | last post by:
Hi, I wrote a DLL Component (using Visual Studio 2005) and managed to include it into a C# Console application. I am now trying to include this component into a Web project. I copy the DLL...
12
by: Keith Patrick | last post by:
Can someone tell me the difference in terms of actual implications using: namespace MyNamespace { using System; class MyClass {...} } vs. using System;
30
by: Pep | last post by:
Is it best to include the code "using namespace std;" in the source or should each keyword in the std namespace be qualified by the namespace tag, such as std::cout << "using std namespace" <<...
3
by: Wayne Shu | last post by:
When I read the chapter of the namespace of the book C++ Primer(3e). It explain the using directive as follow: "A using directive makes the namespace member names visible as if they were declared...
2
by: lewisms | last post by:
Hello all, I am quite new to c++/. Net so please don't shoot me down for being a newbie. Any way I am trying to make a simple multithreading program that is just to learn the ideas behind it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.