help needed on deciphering the g++ vtable dumps
<h3>Source Code</h3>

<pre><code>class W
{
public:
 virtual void f() { cout &lt;&lt; "W::f()" &lt;&lt; endl; }
 virtual void g() { cout &lt;&lt; "W::g()" &lt;&lt; endl; }
};

class AW : public virtual W
{
public:
 void g() { cout &lt;&lt; "AW::g()" &lt;&lt; endl; }
};


class BW : public virtual W
{
public:
 void f() { cout &lt;&lt; "BW::f()" &lt;&lt; endl; }
};

class CW : public AW, public BW
{
};
</code></pre>

<h3>g++ -fdump-class-hierarchy</h3>

<pre><code>Vtable for W  
W::_ZTV1W: 4u entries  
0     (int (*)(...))0  
4     (int (*)(...))(&amp; _ZTI1W)  
8     W::f
12    W::g


Vtable for AW  
AW::_ZTV2AW: 7u entries  
0     0u  
4     0u  
8     0u  
12    (int (*)(...))0  
16    (int (*)(...))(&amp; _ZTI2AW)  
20    W::f  
24    AW::g

VTT for AW  
AW::_ZTT2AW: 2u entries  
0     ((&amp; AW::_ZTV2AW) + 20u)  
4     ((&amp; AW::_ZTV2AW) + 20u)  


Vtable for BW  
BW::_ZTV2BW: 7u entries  
0     0u  
4     0u  
8     0u  
12    (int (*)(...))0  
16    (int (*)(...))(&amp; _ZTI2BW)  
20    BW::f  
24    W::g  

VTT for BW  
BW::_ZTT2BW: 2u entries  
0     ((&amp; BW::_ZTV2BW) + 20u)  
4     ((&amp; BW::_ZTV2BW) + 20u)  

Vtable for CW  
CW::_ZTV2CW: 14u entries  
0     0u  
4     0u  
8     4u  
12    (int (*)(...))0  
16    (int (*)(...))(&amp; _ZTI2CW)  
20    BW::_ZTv0_n12_N2BW1fEv  
24    AW::g  
28    4294967292u  
32    4294967292u  
36    0u  
40    (int (*)(...))-0x00000000000000004  
44    (int (*)(...))(&amp; _ZTI2CW)  
48    BW::f  
52    0u  

Construction vtable for AW (0xb6dbf8c0 instance) in CW  
CW::_ZTC2CW0_2AW: 7u entries  
0     0u  
4     0u  
8     0u  
12    (int (*)(...))0  
16    (int (*)(...))(&amp; _ZTI2AW)  
20    W::f  
24    AW::g  

Construction vtable for BW (0xb6dbf900 instance) in CW  
CW::_ZTC2CW4_2BW: 13u entries  
0     4294967292u  
4     4294967292u  
8     0u  
12    (int (*)(...))0  
16    (int (*)(...))(&amp; _ZTI2BW)  
20    BW::f  
24    0u  
28    0u  
32    4u  
36    (int (*)(...))4  
40    (int (*)(...))(&amp; _ZTI2BW)  
44    BW::_ZTv0_n12_N2BW1fEv  
48    W::g  

VTT for CW  
CW::_ZTT2CW: 7u entries  
0     ((&amp; CW::_ZTV2CW) + 20u)  
4     ((&amp; CW::_ZTC2CW0_2AW) + 20u)  
8     ((&amp; CW::_ZTC2CW0_2AW) + 20u)  
12    ((&amp; CW::_ZTC2CW4_2BW) + 20u)  
16    ((&amp; CW::_ZTC2CW4_2BW) + 44u)  
20    ((&amp; CW::_ZTV2CW) + 20u)  
24    ((&amp; CW::_ZTV2CW) + 48u)  
</code></pre>

<h2>Questions</h2>

<p>What are each of the entries in:</p>

<pre><code>Vtable for AW  
AW::_ZTV2AW: 7u entries  
0     0u          // whats this for???   
4     0u          // ?  
8     0u          // ?  


Vtable for CW  
CW::_ZTV2CW: 14u entries  
0     0u          // ? 
4     0u          // ?     
8     4u          // what is the significance of this ???    
12    (int (*)(...))0  
16    (int (*)(...))(&amp; _ZTI2CW)  
20    BW::_ZTv0_n12_N2BW1fEv   // ?  
24    AW::g  
28    4294967292u   // ?  
32    4294967292u   // ?  
36    0u            // ?  
40    (int (*)(...))-0x00000000000000004  // some delta   
44    (int (*)(...))(&amp; _ZTI2CW)  
48    BW::f  
52    0u  // ?  


CW *pcw = new CW;  
AW *paw = pcw;  
paw-&gt;f();  // Invokes B::f why not w::f
</code></pre>

<p>paw is pointing to AW's vtable and it has a entry of W::f. How does B::f() get called?</p>

<p>Similarly:</p>

<pre><code> BW* pbw = pcw;  
 pbw-&gt;g();  // invokes AW::g() why not w::g  ???
</code></pre>

<p>What is the use of VTT and how its used. VTT of AW contains pointer to vtable of AW<br>
    AW::_ZTT2AW: 2u entries<br>
    0     ((&amp; AW::_ZTV2AW) + 20u)<br>
    4     ((&amp; AW::_ZTV2AW) + 20u)<br>
and both entries at offset 0 and 4 points to vtable base address+20 u = W::f. Why both the entries point to same function of the base class?</p>
