首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >clang 3.1看不到unique_ptr?

clang 3.1看不到unique_ptr?
EN

Stack Overflow用户
提问于 2012-08-08 04:42:32
回答 1查看 8.7K关注 0票数 16

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

代码语言:javascript
复制
#include <memory>
#include <iostream>

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

当我编译时,我得到以下错误:

代码语言:javascript
复制
$ 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:

代码语言:javascript
复制
$ 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

你知道为什么这个不能编译吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-08 04:46:38

我通过使用以下命令来编译它

代码语言:javascript
复制
clang++ test.cpp  -std=c++11 -stdlib=libc++
票数 27
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11853822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档