I\'ve been told it\'s bad to have \"using namespace ns123\" in a header file, but I can\'t remember what the reason given was. Is it in fact a bad thing to do, and why?
If you put a using
declaration in a header file, anything that #include
s the header file also has the namespace imported, whether they want it or not. This violates the principle of least surprise and defeats the purpose of namespaces by allowing changing an #include
statement to easily cause a naming collision. If you want to import a namespace in your own .cpp file to save a little typing and produce more readable code, that's fine. Just don't force users of your module to do the same.