以下两个源文件在可编译性或生成的代码(如果有的话)方面有何不同:
附件 A:
namespace std {};
using namespace std;
#include <vector>
#include <string>
<any code here>
图表 B:
#include <vector>
#include <string>
using namespace std;
<any code here>
假设两个<any code here>
占位符被替换为任何相同的用户代码。
换句话说:如果“使用命名空间标准;”,是否有任何用户可见的差异?放在标准之前 #includes
(假设命名空间std已经如上介绍)?
最佳答案
以下代码可能不太可能出现在您的实现的 vector header 中:
namespace __AA
{
class vector {};
}
namespace std
{
// actual std::vector implementation here
}
namespace __BB
{
using namespace __AA;
vector x;
}
现在有了Exhibit A,你就有点模棱两可了。
关于c++ - "using namespace std;"在 "#include <foo>"之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9952521/