每当我尝试使用带有任何参数的构造函数时,我都会收到编译器错误“没有匹配的函数来调用'make_shared'”。因此,例如:
std::shared_ptr<int> foo = std::make_shared<int> ();
工作正常。但,
std::shared_ptr<int> foo = std::make_shared<int> (10);
给出以下错误:
/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)
我直接从这里获取了上面的代码http://www.cplusplus.com/reference/memory/make_shared/ 并且该代码在 cpp.sh 网站上运行良好。我怀疑我的编译器设置有问题。在 Macbook 上的 iTerm 中运行。此外,即使我删除了上面显示的各种 clang 选项,我也会遇到同样的错误。有任何想法吗?我的头文件是否可能需要更新?它是从 2015 年 9 月 4 日开始的。似乎最近足以让 C++11 工作。
$ /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