16

私は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.

MacOSXでClang3.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

これがコンパイルされない理由はありますか?

4

1 に答える 1

27

を使ってコンパイルしました

clang++ test.cpp  -std=c++11 -stdlib=libc++
于 2012-08-07T20:46:37.610 に答える