I have the following code:
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 it is explained that calling a method of an incomplete type is not possible, nor dereferencing the pointer.
In fact, when I try to compile it I get:
warning: invalid use of incomplete type ‘class Cohomology‘
note: forward declaration of ‘class Cohomology‘
My question is: How can I delegate the construction of EMField
to the Cohomology
class if I cannot use a member of std::unique_ptr<Cohomology> coh
?