Uniquely identifying objects in the presence of multiple inheritance
<p>I'm designing a system that has to intrinsically support history of actions (undo/redo) and serialization. It contains a variety of entities, many are linked as graphs.</p>

<p>I'm at a point where I would like to automate most of the history logging work, by letting the actions know about object creation, destruction and linking. The problem I'm facing is as follows:</p>

<p>Suppose I create object <strong>A</strong>, then object <strong>B</strong>, then link <strong>A</strong> and <strong>B</strong>. Those are three actions. Now undo everything, the actions get moved to the "redo" list. Now, redo everything over again. This means a <em>new</em> <strong>A</strong> object is created, a <em>new</em> <strong>B</strong> object is created. And to redo the linking operation I need to know the "link" action that acted on the <em>old</em> <strong>A</strong> and <strong>B</strong> objects are now to be applied to the <em>new</em> <strong>A</strong> and <strong>B</strong> objects.</p>

<p>A simple relocation table will do the trick; when creating a new object, just map the old address to the new address, and use it to interpret any link relations from the history log. The question is, what happens if multiple inheritance is involved? That is, the link might refer to a pointer to a <em>base</em> of <strong>A</strong>, not <strong>A</strong> itself, so the address might differ from the one in the relocation table.</p>

<p>The system has to handle hundreds of GB in memory, so for performance reasons I would prefer to not just throw away all pointers internally and switch to global unique IDs and perform table lookups all the time. Throwing in a virtual base class for everything is also undesirable, as some of the types are very lightweight.</p>

<p>The question is, is it possible to uniquely identify objects through pointers to one of the (possibly multiple) base classes, other than the two alternatives I mentioned? Should I give up automating this and writing specialized code for each type involved?</p>

<p><strong>EDIT:</strong></p>

<p>Maybe I wasn't clear enough with the long explanation. Here's a simple example to exhibit the problem:</p>

<pre><code>#include &lt;iostream&gt;

using namespace std;

struct A { int x; };

struct B { int y; };

struct AB : A, B { int z; };

int main()
{
    AB ab;

    AB* pab = &amp;ab;
    A* pa = &amp;ab;
    B* pb = &amp;ab;

    cout &lt;&lt; "pab: " &lt;&lt; pab &lt;&lt; endl;
    cout &lt;&lt; "pa: " &lt;&lt; pa &lt;&lt; endl;
    cout &lt;&lt; "pb: " &lt;&lt; pb &lt;&lt; endl;
}
</code></pre>

<p>One possible output is:</p>

<pre><code>pab: 0x7fff30b6a400
pa: 0x7fff30b6a400
pb: 0x7fff30b6a404
</code></pre>

<p>As you can see, <code>pb</code> has a different value than <code>pab</code>, even though they came from the same object. I need a way to know that they both identify the same object, the reason was described above (the do/undo operations might recreate the object in a new place, so all pointers to it have to be updated.)</p>
