I'm working on an application that has the following problem. Basically there are a lot of object that implicitly might destroy themselves.
void Foo::func()
{
...
Bar b;
b.func2();
}
Here the func2 might destroy the foo object calling it. Since it is not very obvious that this might happen I would like to make sure that no member variables of the foo object can be accessed after this call, since I cannot guarantee they are still valid. If this call to b is the last call I am perfectly fine, but since I am not the only one working on this project and the destruction is not obvious I would like to implement something to block usage this after these calls. Is there a way to implement this without completely refactoring the current design (since it is use extensively thoughout the project)?
Some background info:
It is a Qt UI application that uses QML to keep track of a stack of "screens" (a screen is a QML + its corresponding C++ model). The Bar class in my example is the 'stack manager' which controls the lifetime of the screens. It is a singleton (I know). The Foo class is a C++ model for a specific QML. The function Foo::func() is a function that can be called either from user input in the QML or another system event. The function normally processes the event, but occasionaly it can tell the screen manager to delete one or more screen(s), which in turn deletes the model corresponding to that screen (which might be the calling model).