该的std :: shared_ptr的构造不表现如我所料:
#include <iostream>
#include <vector>
void func(std::vector<std::string> strings)
{
for (auto const& string : strings)
{
std::cout << string << '\n';
}
}
struct Func
{
Func(std::vector<std::string> strings)
{
for (auto& string : strings)
{
std::cout << string << '\n';
}
}
};
int main(int argc, const char * argv[])
{
func({"foo", "bar", "baz"});
Func({"foo", "bar", "baz"});
//auto ptr = std::make_shared<Func>({"foo", "bar", "baz"}); // won't compile.
//auto ptr = std::make_shared<Func>{"foo", "bar", "baz"}; // nor this.
return 0;
}
我是不是做错了什么或者是编译器? 编译如下:
$铛++ --version苹果铛版本4.0(标签/苹果/铛 - 421.0.57)(基于LLVM 3.1svn)
编辑:shared_ptr的,而不是make_shared。
这里的错误:
make -k
clang++ -std=c++11 -stdlib=libc++ main.cc -o main
main.cc:28:18: error: no matching function for call to 'make_shared'
auto ptr = std::make_shared<Func>({"foo", "bar", "baz"});
^~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/c++/v1/memory:4621:1: note: candidate function not viable:
requires 0 arguments, but 1 was provided
make_shared(_Args&& ...__args)
^
1 error generated.