我尝试在复制构造函数中运行此代码以将 unique_ptr 从第一个向量移动到另一个向量:
class Text
{
struct paragraph
{
int index;
string text;
};
vector<unique_ptr<paragraph>> paragraphs;
public:
Text()
{
paragraphs.push_back(unique_ptr<paragraph>(new paragraph));
}
Text(const Text & t)
{
for(int i = 0; i < (int)t.paragraphs.size(); i++)
{
paragraphs.push_back(move(t.paragraphs[i]));
}
}
};
我得到了这个错误:
1>c:\program files\microsoft visual studio 10.0\vc\include\xmemory(208): error C2248: 'std::unique_ptr<_Ty>::unique_ptr' : cannot access private member declared in class 'std::unique_ptr<_Ty>'
1> with
1> [
1> _Ty=Text::paragraph
1> ]
// Etc.