title: Are inline virtual functions really a non-sense?
body: <p>I got this question when I received a code review comment saying virtual functions need not be inline. </p>
  
  <p>I thought inline virtual functions could come in handy in scenarios where functions are called on objects directly. But the counter-argument came to my mind is -- why would one want to define virtual and then use objects to call methods?</p>
  
  <p>Is it best not to use inline virtual functions, since they're almost never expanded anyway?</p>
  
  <p>Code snippet I used for analysis:</p>
  
  <pre><code>class Temp
  {
  public:
  
      virtual ~Temp()
      {
      }
      virtual void myVirtualFunction() const
      {
          cout&lt;&lt;"Temp::myVirtualFunction"&lt;&lt;endl;
      }
  
  };
  
  class TempDerived : public Temp
  {
  public:
  
      void myVirtualFunction() const
      {
          cout&lt;&lt;"TempDerived::myVirtualFunction"&lt;&lt;endl;
      }
  
  };
  
  int main(void) 
  {
      TempDerived aDerivedObj;
      //Compiler thinks it's safe to expand the virtual functions
      aDerivedObj.myVirtualFunction();
  
      //type of object Temp points to is always known;
      //does compiler still expand virtual functions?
      //I doubt compiler would be this much intelligent!
      Temp* pTemp = &amp;aDerivedObj;
      pTemp-&gt;myVirtualFunction();
  
      return 0;
  }
  </code></pre>