C++ 错误C2248:&x27;标准::唯一性\u ptr<_Ty>;::唯一的ptr';:无法访问类';标准::唯一性\u ptr<_Ty>';

C++ 错误C2248:&x27;标准::唯一性\u ptr<_Ty>;::唯一的ptr';:无法访问类';标准::唯一性\u ptr<_Ty>';,c++,visual-studio-2012,c++11,C++,Visual Studio 2012,C++11,目前,我正在尝试使用std::unique_ptr,但在Visual Studio 2012中遇到编译器错误 class A { private: unique_ptr<A> other; public: unique_ptr<A> getOther() { return other; } }; A类 { 私人: 独特的,独特的; 公众: 唯一的\u ptr getOther() { 归还他人; } }; 错误是: error C2248: 'std::

目前,我正在尝试使用
std::unique_ptr
,但在Visual Studio 2012中遇到编译器错误

class A
{
private:
 unique_ptr<A> other;
public:
 unique_ptr<A> getOther()
 {
   return other;
 }
};
A类
{
私人:
独特的,独特的;
公众:
唯一的\u ptr getOther()
{
归还他人;
}
};
错误是:

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
]
错误C2248:'std::unique\u ptr::unique\u ptr':无法访问在类'std::unique\u ptr'中声明的私有成员
具有
[
_Ty=A
]
c:\ProgramFiles(x86)\microsoft visual studio 11.0\vc\include\memory(1447):请参阅“std::unique\u ptr::unique\u ptr”的声明
具有
[
_Ty=A
]

我相信
std::unique\u ptr
可以是一种返回类型,如果返回的值是本地范围的(即,它一离开函数就被销毁)。在您的情况下,它不是,因为您返回的是
unique\u ptr other
,它在类有效时具有生存时间。

您无法复制unique\u ptr,因为。。。它们是独一无二的。(提示:您正在按值返回指针,这将生成一个副本)如果您想要多个副本,为什么要使用
unique\u ptr
。。。我被这个错误弄糊涂了。现在我得到了确切的问题。