How to find the immediate parent of the derived class
<p>Suppose I have a base class B, derived class D, derived derived class DD.
How can I get the instance of the immediate parent to my current object?</p>

<p>e.g.</p>

<pre><code>DD dd;
if (condition )
  dd-&gt;myfunction();
else
  d = getcurrentparent(); // this should give the current parent, here D d;
</code></pre>

<p>Edit:</p>

<p>Ok I am adding my scenario.</p>

<p>Its like an Menu. And each menu is different class. </p>

<p>main menu - base class
sub menu - derived class
sub sub menu - derived derived class.</p>

<p>Now when I am traversing in the sub sub menu, I need to know the immediate parent of the current obj (like going back from sub sub menu to sub menu)</p>
