4
在下面的代码中,是避免编译错误并包含Bh的唯一方法,它在A.cpp中手动实现移动构造函数/赋值?“使用未定义类型”和unique_ptr转发已声明的类和默认的移动构造函数/赋值
// A.h
#include <memory>
class B; // implementation somewhere in B.h/B.cpp
class A
{
public:
A() = default;
~A() = default;
A(const A&) = delete;
A& operator=(const A&) = delete;
A(A&&) = default;
A& operator=(A&&) = default;
private:
std::unique_ptr<B> m_b;
};
的Visual Studio 2015年提供了“错误C2027:使用未定义的类型”,因为的std ::的unique_ptr呼吁M_B的缺失者的移动构造函数/赋值运算符(在试图调用B的析构函数),这显然是不在这一点上已知。
相关/ dup:http://stackoverflow.com/questions/13414652/forward-declaration-with-unique-ptr – NathanOliver
我其实也不知道你也可以在.cpp中默认。我认为这是需要申报的。因此,处理我的具体情况的正确方法就是将移动构造器声明为A(A &&)noexcept;在A.h中并将其定义为A :: A(A &&)noexcept = default;在A.cpp。谢谢! – Robert
这听起来像个好主意。 – NathanOliver