CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 1999
    Location
    Slovenia (currently: Germany)
    Posts
    249

    Namespace pollution?

    I am just wondering if I use
    using namespace std;
    in my header .h file, does it stop at the end of header file or it pollutes every .cpp file that includes this header.

    Tomaz


  2. #2
    Join Date
    Jul 1999
    Location
    Moscow, Russia
    Posts
    667

    Re: Namespace pollution?

    Hi,
    if you put using namespace std;in the header .h file - it pollutes every .cpp file that includes this header, as so the declarations of namespace is visible in the scope of a translation unit and #include adds *.h and *.cpp in the single translation unit.


    Hope this helps,
    Oleg.


  3. #3
    Join Date
    May 1999
    Location
    Slovenia (currently: Germany)
    Posts
    249

    Re: Namespace pollution?

    I guess that means that it is bad karma to include using statement in header files since there is no way to terminate the effect of it(?)

    And if I declareMyClass::say_it(std::string sWord);

    in header file and implement it likeusing namespace std;
    MyClass::say_it(string sWord)

    in my implementation file class wizard won't match the declaration and implementation of functions.

    Sniff, sniff...What do to?

    Sincerely,
    Tomaz


  4. #4
    Join Date
    Jun 1999
    Location
    Miami, FL
    Posts
    972

    Re: Namespace pollution?

    I guess the only viable solution is to also implement it with the std:: for ClassWizard's sake, like this:

    using namespace std;

    MyClass::say_it(std::string sWord)
    {
    // But in here you can omit the std::
    string sAnotherWord = sWord;
    }



    Cheers!
    Alvaro


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured