LLVM编译器2.0:警告"使用命名空间std;"

Jus*_*kva 17 c++ xcode namespaces llvm clang

在使用LLVM 2.0的Xcode中,当我将该行using namespace std;放入我的C++代码中时,我收到此警告:

语义问题
使用指令是指隐式定义的命名空间'std'

有没有办法来解决这个问题?为什么要发出警告?

Mot*_*tti 28

你有没有包含任何标准的头文件?否则编译器不知道namespace std.

请发布更多代码以澄清.

  • 啊,我刚想通了.你是对的,`using namespace std;`这一行是文件中的第一行(除了#ifndef和#define语句之外); 我在`#include <iostream>`之后移动了它,它消除了警告.海湾合作委员会从未发出过这样的警告,所以我以前从没想过.谢谢! (4认同)

小智 8

将using namespace std移动到#include之后可以消除此警告.


小智 6

我这样解决了这个问题

#include <iostream>

using namespace std;
/// This function is used to ensure that a floating point number is
/// not a NaN or infinity.
inline bool b2IsValid(float32 x)
{
    if (x != x)
    {
        // NaN.
        return false;
    }
    float32 infinity = std::numeric_limits <float32>::infinity();
    return -infinity < x && x < infinity;
    return true;

}
Run Code Online (Sandbox Code Playgroud)