I have 2 classes: DataObject
and DataElement
. DataObject
holds pointers to (only) DataElement
s, and a DataElement
Make the destructor for the first class defined outside of the class body and after the second class, e.g.
class DataElement;
class DataObject
{
DataElement* elem;
public:
~DataObject();
};
class DataElement
{
DataObject* obj;
public:
~DataElement() { delete obj; }
};
DataObject::~DataObject()
{
delete elem;
}
Define the destructor in a .cpp file that includes both headers.