只要我不将构造函数(of B
)的定义移到标头,代码就可以工作B.h
。
h
class Imp; //<--- error here
class B{
public:
std::unique_ptr<Imp> imp;
B(); //<--- move definition to here will compile error
~B();
//// .... other functions ....
};
丙型肝炎
#include "B.h"
#include "Imp.h"
B::B(){ }
~B::B(){ }
进出口
class Imp{};
Main.cpp(编译我)
#include "B.h"
错误:删除指向不完整类型的指针
错误:使用未定义的类型'Imp'C2027
我可以以某种方式理解必须将析构函数移至.cpp
,因为的析构Imp
可能称为:-
delete pointer-of-Imp; //something like this
但是,我不明白为什么规则也涵盖构造函数(问题)。
我读过了 :-
.cpp
。如果构造函数异常退出,则构造函数需要销毁该类成员。
我认为使构造函数noexcept
无济于事,尽管也许可以。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句