gpt4 book ai didi

c++ - clang 3.1 看不到 unique_ptr?

转载 作者:IT老高 更新时间:2023-10-28 22:18:50 24 4
gpt4 key购买 nike

我刚刚开始玩 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com