title: Virtual method VS std::function member variable in terms of performance
body: <p>A game engine has this class :</p>
  
  <pre><code>class  MouseListener{
  public :
  MouseListener();
  virtual void OnMouseDown(int mx,int my);
  virtual void OnMouseUp(int mx,int my);
  .
  .
  .
  };
  </code></pre>
  
  <p>Each object that wants to listen to mouse input , have to inherent that class and override it's methods . To not have to declare a new type each  time , the class is modified to :</p>
  
  <pre><code>class  MouseListener{
  public :
  MouseListener();
  std::function &lt;void(MouseListener*,int,int)&gt;OnMouseDown;
  std::function &lt;void(MouseListener*,int,int)&gt;OnMouseUp;
  .
  .
  .
  };
  </code></pre>
  
  <p>now using the class can be done this way  :</p>
  
  <pre><code>MouseListener * m = new MouseListener();
  m-&gt;OnMouseDown = [](MouseListener * thiz,int x,int y){
     //// do something
  };
  </code></pre>
  
  <p>From the input system , only the functions of MouseListener that are not null ( assigned ) are called ( with thiz = the mouse listener ).
  knowing that the class is used from an external library ( static link ) , which is better in terms of performance ?</p>
  
  <p><strong>NOTE : None of those function will be called unless a mouse event is received , when that happens , the appropriate function is called for each object listening to mouse input ( not supposed to be lot  , &lt;50)</strong></p>