title: c++ virtual table lookup - how does it search & replace
body: <p>Lets take below example:</p>
  
  <pre><code>class Base{
      virtual string function1(){ return "Base - function1"; };
      virtual string function2(){ return "Base - function2"; };
  };
  
  class Derived : public Base {
      virtual string function2(){ return "Derived - function2"; };
      virtual string function1(){ return "Derived - function1"; };
      string function3() { return "Derived - function3"; };
  };
  </code></pre>
  
  <p>So the vtable structure is like</p>
  
  <pre><code>Base-vTable
  -----------------------
  name_of_function address_of_function
  function1   &amp;function1
  function2   &amp;function2
  -----------------------
  -----------------------
  Derived-vTable
  -----------------------
  name_of_function address_of_function
  function1   &amp;function1
  function2   &amp;function2
  </code></pre>
  
  <p>or is it like</p>
  
  <pre><code>    Base-vTable
  -----------------------
      Offset function
      +0  function1
      +4  function2
  -----------------------
  -----------------------
      Derived-vTable
  -----------------------
      Offset function
      +0  function1
      +4  function2
  </code></pre>
  
  <p>If it is like latter? then what is that offset? where is it used?</p>
  
  <p>And the function name:
  Is it mangled function name? if it is mangled then the base and derived mangled names wont match and the vtable lookup wont work.
  Compiler does mangle all the virtual function names so it must be a mangled name, does it mean that the mangled name for base &amp; derived is same in case it is virtual function.</p>