铛3.1看不见的unique_ptr?(clang 3.1 can't see unique

2019-07-30 20:45发布

我刚开始铿锵玩弄,并试图编译下面的示例程序:

#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.

我使用锵3.1在Mac OS X:

$ 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

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

Answer 1:

我把它用编译

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


文章来源: clang 3.1 can't see unique_ptr?
标签: c++ c++11 clang