Re: "using namespace std" causing soooo many errors

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: frank sinatra (frank_at_spamoff.net)
Date: 03/08/04


Date: Mon, 8 Mar 2004 11:57:46 +0200


> The solution is to never, ever, ever put "using namespace std" in a
> header file. That means you expose all of std to all files that include
> this header file, and you end up with problems like the above.
> Namespaces are there for a reason.

#include <string>

namespace foo {

using std::string;

// ... mystuff ...

}

I do that without problems, I thought typedefs and using statements were
properly scoped. Using a whole namespace in similiar way with C++ standard
conformant compiler shouldn't bring out too much issues.. not that I would
recommend doing it, and naturally I would better avoid using same symbols
the std:: is using, ah, I see what this is about, sorry for wasting the
bandwidth. But atleast the GLOBAL namespace would be safe, until someone
decides to use namespace "bar" (the one inside which we would be using all
of the std..)

Just joking, I am not sorry, the point was that hand-picking some classes
like above can be handy now and then!



Relevant Pages

  • Re: Elegant way to do this?
    ... > cin or wahtever is preceeded by a namespace resolution ... To then expose all names within the namespace, ... and have exposed the entire 'std' namespace. ... Will my code compile? ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Some sort of append algorithm...
    ... It's in the 'iterator' header file. ... It's a function template in the ... 'std' namespace. ...
    (comp.lang.cpp)
  • Re: friend operator << overload ambiguity error
    ... > standard. ... > users to add names to namespace std under the right circumstances. ... A program may add template specializations for any standard library template ...
    (comp.lang.cpp)
  • Re: location of using, include, and namespaces statement
    ... #ifndef H_TREE ... functions they declare are *not* part of your namespace! ... The first rule is to make the header file idempotent; ... Since the user never sees the .cxx file (that is, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: MC++ DLL (VS.2003) compiler errors...(sigh!)
    ... I have been working on trying to create a DLL written in MC++. ... Interfaces go into header file but that's all I think I have right. ... using namespace System::IO; ... Int32 line; ...
    (microsoft.public.dotnet.languages.vc)