【发布时间】:2022-08-09 22:13:39
【问题描述】:
我有以下代码:
class Cohomology;
struct EMField
{
std::unique_ptr<Cohomology> coh;
std::array<DIM> data;
EMField() {coh -> initializeField(*this);};
}
class Cohomology
{
private:
// private members
public:
Cohomology(PList params)
{
// Constructor of the class
}
void initializeField(EMField& field)
{
field.coh.reset(this);
// other methods to initialize field.data using the private members
}
}
In this answer 解释了调用不完整类型的方法是不可能的,也不能取消引用指针。
事实上,当我尝试编译它时,我得到:
warning: invalid use of incomplete type ‘class Cohomology‘
note: forward declaration of ‘class Cohomology‘
我的问题是:如果我不能使用std::unique_ptr<Cohomology> coh 的成员,我如何将EMField 的构造委托给Cohomology 类?
标签: c++