Is it wrong to use C++ 'using' keyword in a header file?

前端 未结 5 770
[愿得一人]
[愿得一人] 2020-12-19 00:28

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?

5条回答
  •  悲哀的现实
    2020-12-19 00:56

    It's a bad practice, in general, because it defeats the purpose of namespaces. By defining in a header you're not enforcing strict control over the scope of the using declaration, meaning that you can run into name clashes in unexpected places.

提交回复
热议问题