jav*_*ver 6 c++ pimpl-idiom unique-ptr
只要我不将构造函数(of B
)的定义移动到头部,代码就会工作B.h
.
BH
class Imp; //<--- error here
class B{
public:
std::unique_ptr<Imp> imp;
B(); //<--- move definition to here will compile error
~B();
//// .... other functions ....
};
Run Code Online (Sandbox Code Playgroud)
B.cpp
#include "B.h"
#include "Imp.h"
B::B(){ }
~B::B(){ }
Run Code Online (Sandbox Code Playgroud)
Imp.h
class Imp{};
Run Code Online (Sandbox Code Playgroud)
Main.cpp (编译我)
#include "B.h"
Run Code Online (Sandbox Code Playgroud)
错误:删除指向不完整类型的指针
错误:使用未定义类型'Imp'C2027
我可以以某种方式理解析构函数必须被移动到.cpp
,因为Imp
可能会被称为析构: -
delete pointer-of-Imp; //something like this
Run Code Online (Sandbox Code Playgroud)
但是,我不明白为什么规则也涵盖了构造函数(问题).
我读过了 :-
.cpp
. 归档时间: |
|
查看次数: |
663 次 |
最近记录: |