RayLivingston:
The fact that you need to make that kind of circular reference is a good indication that your class hierarchy is seriously flawed, and you need to put more thought into how you abstract things. Data/information flow should be one direction.
Regards,
Ray L.
I think that statement is quite a lot stronger than it needs to be. There are perfectly valid reasons why you might have circular calling references like that.
For example, at my job we have a particular piece of software that uses what is called a utility file that contains interpreted instructions that direct the program to perform certain sequences of events. The file contains a numbered sequence of steps, and each set has a set of goto fields that say which step number to go to next depending on the result of the step.
To help programmatically generate these files, I created my own program with separate classes called utility, step, and goto_field.
For the goto field, I created 3 different ways of referring addressing the step that would be converted to the proper step number when it was written out to file: absolute (Step #), relative (next step, or 3 steps back), and pointer (this specific step, no matter where it may be rearranged in the list).
So suppose I have a goto_field referring to a step by its pointer, and the step it's pointing to is deleted in the course of the utility object. I now have a dangling pointer to something that no longer exists. How do I fix that?
The easiest way I came up to do it was to have the step class track all the goto_fields that were pointing to it. When the goto field pointed to the step, it called a step::register_reference function that added a pointer to itself to the step's list. When it no longer pointed to that step (or was destroyed) it unregistered the reference.
In step's destructor, I have it loop through all the references in the list and call the set_invalid() function to set the goto's reference pointer to nullptr.
So step is calling functions on goto_field pointers, and goto_fields are calling functions on step pointers.