【发布时间】:2017-07-12 07:41:39
【问题描述】:
我指的是question,我们能否为已删除默认构造函数的类创建一个std::unique_ptr数组,如下所示,如何传递string参数。
#include <iostream>
#include <string>
#include <memory>
using namespace std;
class A
{
string str;
public:
A() = delete;
A(string _str): str(_str) {}
string getStr()
{
return str;
}
};
int main()
{
unique_ptr<A[]> ptr = make_unique<A[]>(3);
unique_ptr<A[]> arr[3] = make_unique<A[]>(3);
// Do something here
return 0;
}
【问题讨论】:
-
您询问的是
std::unique_ptr数组,但您有std::unique_ptr到数组。 -
请澄清您的意思是代码中的“unique_ptr 到数组”还是“智能指针数组”
标签: c++ visual-c++ c++14