title: Calling virtual function from destructor
body: <p>Is this safe ?</p>
  
  <pre><code>class Derived:  public PublicBase, private PrivateBase
  {
   ... 
  
     ~Derived()
     {
        FunctionCall();
     }
  
     virtual void FunctionCall()
     {
        PrivateBase::FunctionCall();
     }
  }
  
  class PublicBase
  {
     virtual ~PublicBase(){};
     virtual void FunctionCall() = 0;
  }
  
  class PrivateBase
  {
     virtual ~PrivateBase(){};
     virtual void FunctionCall()
     {
      ....
     }
  }
  
  
  PublicBase* ptrBase = new Derived();
  delete ptrBase;
  </code></pre>
  
  <p>This code crases <strong><em>sometimes</em></strong> with IP in a bad address.</p>
  
  <p>That is not a good idea to call a virtual function on constructor is clear for everyone.</p>
  
  <p>From articles like <a href="http://www.artima.com/cppsource/nevercall.html" rel="noreferrer">http://www.artima.com/cppsource/nevercall.html</a> I understand that destructor is also a not so good place to call a virtual function.</p>
  
  <p>My question is "Is this true ?" I have tested with VS2010 and VS2005 and PrivateBase::FunctionCall is called. Is undefined behavior ? </p>