我在 VS2013 中收到以下代码错误...
class Bob
{
private:
std::vector<std::unique_ptr<UnrelatedClass>> _aVector;
inline Bob(const Bob & other) {};
inline Bob & operator=(const Bob & other) { return *this; };
public:
Bob();
~Bob();
Bob(Bob && o);
};
class Fred
{
friend class Bob;
[... A few functions, Bob never used ...]
};
...删除后编译得很好friend class Bob;
。这是编译器错误吗?我不确定我做错了什么。
错误如下:
c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(615): error C2248: 'std::unique_ptr<Unrelated,std::default_delete<_Ty>>::unique_ptr' : cannot access private member declared in class 'std::unique_ptr<Unrelated,std::default_delete<_Ty>>'
with
[
_Ty=Unrelated
]
c:\program files (x86)\microsoft visual studio 12.0\vc\include\memory(1487) : see declaration of 'std::unique_ptr<Unrelated,std::default_delete<_Ty>>::unique_ptr'
with
[
_Ty=Unrelated
]
c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(614) : while compiling class template member function 'void std::allocator<_Ty>::construct(_Ty *,const _Ty &)'
with
[
_Ty=std::unique_ptr<Unrelated,std::default_delete<Unrelated>>
]
c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(752) : see reference to function template instantiation 'void std::allocator<_Ty>::construct(_Ty *,const _Ty &)' being compiled
with
[
_Ty=std::unique_ptr<Unrelated,std::default_delete<Unrelated>>
]
c:\program files (x86)\microsoft visual studio 12.0\vc\include\type_traits(580) : see reference to class template instantiation 'std::allocator<_Ty>' being compiled
with
[
_Ty=std::unique_ptr<Unrelated,std::default_delete<Unrelated>>
]
c:\program files (x86)\microsoft visual studio 12.0\vc\include\vector(650) : see reference to class template instantiation 'std::is_empty<_Alloc>' being compiled
with
[
_Alloc=std::allocator<std::unique_ptr<Unrelated,std::default_delete<Unrelated>>>
]
c:\...\include\bob.h(51) : see reference to class template instantiation 'std::vector<std::unique_ptr<Unrelated,std::default_delete<_Ty>>,std::allocator<std::unique_ptr<_Ty,std::default_delete<_Ty>>>>' being compiled
with
[
_Ty=Unrelated
]
研究使我明白这Bob
是复制时产生的相同错误。因此,复制std::vector
,因此复制std::unique_ptr