c++ - clang 3.1 看不到 unique_ptr?

标签 c++ c++11 clang

我刚刚开始玩 clang 并尝试编译以下示例程序:

#include <memory>
#include <iostream>

int main()
{
    std::unique_ptr<unsigned> u(new unsigned(10));
    std::cout << *u << std::endl;
    return 0;
}

编译时出现以下错误:

$ clang++ helloworld.cpp 
helloworld.cpp:6:10: error: no member named 'unique_ptr' in namespace 'std'
    std::unique_ptr<unsigned> u(new unsigned(10));
    ~~~~~^
helloworld.cpp:6:29: error: expected '(' for function-style cast or type construction
    std::unique_ptr<unsigned> u(new unsigned(10));
                    ~~~~~~~~^
helloworld.cpp:6:31: error: use of undeclared identifier 'u'
    std::unique_ptr<unsigned> u(new unsigned(10));
                              ^
helloworld.cpp:7:19: error: use of undeclared identifier 'u'
    std::cout << *u << std::endl;
                  ^
4 errors generated.

我在 Mac OS X 上使用 Clang 3.1:

$ clang++ --version
Apple clang version 3.1 (tags/Apple/clang-318.0.61) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.0
Thread model: posix

任何想法为什么这不会编译?

最佳答案

我用它编译了

clang++ test.cpp  -std=c++11 -stdlib=libc++

关于c++ - clang 3.1 看不到 unique_ptr?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11853822/

相关文章:

c++ - 函数 try block 是否允许我们解决异常?

c++ - 模板关键字作为模板参数

c++ - 为什么〜size_t(0)(在大多数32位系统中== 0xFFFFFFFF)不是有效的数组索引?

c++ - 优化 C++11 随机生成器的使用

c++ - 我可以假设分配器不直接持有它们的内存池(因此可以被复制)吗?

xcode - clang:错误:Mac OSX Mavericks 上不受支持的选项 '-static-libgcc'

c++ - 最大化的 WS_POPUP 窗口位于任务栏前面

c++ - 在 C++ 中对 std::atomic<bool> 使用比较和读/写操作?

python - 使用python模块numba时出错

c++ - 使用来自 clang 的进位代码产生良好的添加