在头文件中使用C ++'using'关键字是否错误? [英] Is it wrong to use C++ 'using' keyword in a header file?

查看:93
本文介绍了在头文件中使用C ++'using'关键字是否错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人告诉我在头文件中使用使用命名空间ns123"是不好的,但是我不记得给出的原因是什么.实际上这是一件坏事吗,为什么?

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?

推荐答案

通常,这是一种不好的做法,因为它违反了名称空间的目的.通过在标头中进行定义,您并不需要对using声明的范围进行严格控制,这意味着您可能在意料之外的地方遇到名称冲突.

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.

这篇关于在头文件中使用C ++'using'关键字是否错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆