C ++:当我使用“using namespace xyz”时会发生什么? before#include< headerxy> [英] C++: What's happen when I use "using namespace xyz" before #include<headerxy>
本文介绍了C ++:当我使用“using namespace xyz”时会发生什么? before#include< headerxy>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
使用命名空间std的排序;包括?
我听说强烈禁止使用using namespace xy之前的#include。例如
I heard that it is strongly prohibited to use "using namespace xy" before "#include ". E.g.
#include <iostream>
using namespace std;
int main() {
...
}
$ b b
这是什么技术原因?我尝试下面,它工作没有任何问题:
What's the technical reason for that? I tried following and it worked without any problems:
using namespace std;
#include <iostream>
int main() {
....
}
推荐答案
不,它不是强烈禁止(否则会是一个编译或预处理错误)。
No, it is not strongly prohibited (otherwise it would be a compilation or preprocessing error).
使用
关键字将所有函数和变量放入当前命名空间,并且不鼓励在头文件中使用它。
The using
keyword puts all functions and variable into the current namespace, and it is discouraged to use it in the header files.
这篇关于C ++:当我使用“using namespace xyz”时会发生什么? before#include< headerxy>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文