title: Indirect call of virtual function from Destructor
body: <p><em><strong>Let me make this disclaimier :</strong> I have clear understanding of virtual function call in Constructor or Destructor.</em></p>
  
  <p>In the below code I am trying to avoid virtual destructor ONLY FOR EXPERIMENTAL purpose.</p>
  
  <p>Now my question is:</p>
  
  <p>In main the call to Destroy fun calls the right virtual function.
  I am expecting any call to Destroy Function should call the right virtual fun.</p>
  
  <p>But the same Destroy function placed in Base destructor call's the Base virtual function.</p>
  
  <p>Is this related to static binding or compiler optimization?</p>
  
  <pre><code>class Base
  {
  public:
        Base()
        {
        }
        void Destroy()
        {
              callVirtual();
        }
        virtual void callVirtual()
        {
              cout&lt;&lt;"In Base callVirtual "&lt;&lt;endl;
        }
        ~ Base()
        {
             cout&lt;&lt;"In Base Destructor"&lt;&lt;endl;
  
             Destroy();
        }
  };
  </code></pre>
  
  <p>.</p>
  
  <pre><code>class Derived : public Base
  {
     public:
             Derived()
             {
             }
             void callVirtual()
             { 
                 cout"&lt;&lt;In Derived callVirtual"&lt;&lt;endl;
             } 
  };
  </code></pre>
  
  <p>.</p>
  
  <pre><code>int main()
  {
      Base *pointer = new Derived();
  
      pointer-&gt;Destroy();    // Calls the right callVirtual
  
   return 0;
  
  }
  </code></pre>