Since, from the moment of calling the destructor for the child user, the parent destructor has already completed (dtors for member objects starts after dtor for the containing object), even if the child had a simple pointer to the parent, the call to the parent member function will be invalid at the time point ~Child() .
You may be able to get around this with a child call to getSystem() at some earlier point and caching the result. Maybe in the Child constructor (if at that time it refers to the parent), or maybe an interface can be added so that Parent can let the child know that he needs to collect everything that he might need during the destruction of the parent element in this time.
I understand that none of them is an excellent solution (it increases the adhesion of objects) - I hope someone publishes the best option.
source share