Click to See Complete Forum and Search --> : Namespace pollution?


Tomaz Stih
October 11th, 1999, 05:19 AM
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

Oleg Lobach
October 12th, 1999, 07:43 AM
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.

Tomaz Stih
October 12th, 1999, 09:23 AM
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

ALM
October 12th, 1999, 11:03 AM
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