C++11 对';使#u共享';

C++11 对';使#u共享';,c++11,clang,llvm,make-shared,C++11,Clang,Llvm,Make Shared,每当我尝试使用带有任何参数的构造函数时,都会出现编译器错误“调用'make_shared'时没有匹配函数”。例如: std::shared_ptr<int> foo = std::make_shared<int> (); 错误消息抱怨您使用了prvalue10。尝试使用 int avar = 10; auto foo = std::make_shared<int> (avar); int-avar=10; 自动foo=std::使_共享(avar); 看

每当我尝试使用带有任何参数的构造函数时,都会出现编译器错误“调用'make_shared'时没有匹配函数”。例如:

std::shared_ptr<int> foo = std::make_shared<int> ();

错误消息抱怨您使用了prvalue
10
。尝试使用

int avar = 10;
auto foo = std::make_shared<int> (avar);
int-avar=10;
自动foo=std::使_共享(avar);
看看使用左值时会发生什么是很有趣的

您是否在本地建立了std库?如果你是,也许你可以尝试重新构建或者从某处获取一个预构建的库

我使用配置
x86-64 clang7.0.0
-std=c++11
对代码进行了测试。它很好用。即使你使用的是iOS,我想在这个操作系统上也应该很好


我还看到您在构建时使用了
-Wc++11扩展。试着用
-std=c++11
来代替,也许吧?

你有什么版本的Clang?这是一个共享的
。#包括$/usr/bin/clang--版本Apple LLVM版本7.0.2(clang-700.1.81)目标:x86_64-Apple-darwin17.7.0线程模型:posixYES,#包括。。。代码的测试与这里显示的完全一样:我应该在问题中添加我以前尝试使用右值的内容。它起作用了。但我不应该在那里使用右值。然而,最后你却一针见血-std=c++11'成功了!!谢谢。它在谷歌上搜索了一下,可能不正确,但是
-Wc++11扩展名
似乎是有效的,而且是针对一个非常旧版本的clang。我猜在那个版本中,可能是由于某些原因,当时没有实现右值引用构造函数。如果它有效,请勾选:)接受我的回答,谢谢
/usr/bin/clang  -g -Wall -Wextra -Wc++11-extensions -c ./test.cpp
./test.cpp:7:30: error: no matching function for call to 'make_shared'
  std::shared_ptr<int> foo = std::make_shared<int> (10);
                         ^~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:4700:1: note: candidate function [with _Tp = int, _A0 = int]
  not viable: expects an l-value for 1st argument
make_shared(_A0& __a0)
$ /usr/bin/clang --version
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin17.7.0
Thread model: posix

$ ls -l /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory
-rw-r--r--  1 root  wheel  174919 Sep  4  2015 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory
int avar = 10;
auto foo = std::make_shared<int> (avar);