Using namespace

When learning C++, frequently people will tell you to use “using namespace std” or some other namespace like “boost”. What they don’t tell you is that you’re never supposed to use it in a header file. You’re only supposed to use it in cpp files. If you use it in a header file, every included after that directive will be using that directive. It could lead to name clashes and other issues. Also, if you put it in a header, you may unintentionally be using that directive without even knowing it, which can cause serious headaches.

Leave a Reply

You must be logged in to post a comment.