Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why using directive in C++ is not encouraged?

Tags:

c++

I read that using directive is not encouraged in C++ saying never put using directives in header files. Why is it like that? Any hint for me?

Thanks!

like image 240
skydoor Avatar asked Jan 06 '10 19:01

skydoor


1 Answers

using namespace x; is a very bad idea, since you have no idea what names you are importing, even with the standard library.

However: using std::cout; and similar statements are a very good idea, because they import symbols explicitly, and make code more readable (though it still might not be a good idea to put them in the global scope in header files).

like image 194
James Avatar answered Oct 16 '22 16:10

James