2
目前,我试图用一个std::unique_ptr
,但我在Visual得到一个编译器错误工作室2012年错误C2248:“的std ::的unique_ptr <_Ty> ::的unique_ptr”:不能访问类中声明私有成员“的std ::的unique_ptr <_Ty>”
class A
{
private:
unique_ptr<A> other;
public:
unique_ptr<A> getOther()
{
return other;
}
};
和错误是:
error C2248: 'std::unique_ptr<_Ty>::unique_ptr' : cannot access private member declared in class 'std::unique_ptr<_Ty>'
with
[
_Ty=A
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\memory(1447) : see declaration of 'std::unique_ptr<_Ty>::unique_ptr'
with
[
_Ty=A
]
你不能复制unique_ptr,因为......它们是唯一的。 (提示:您将按照值返回指针,这会生成副本) – Borgleader
如果您需要多个副本,为什么使用'unique_ptr'? –
好的...我对这个错误感到困惑。现在我得到了确切的问题。 – arunkn