title: Ways to detect whether a C++ virtual function has been redefined in a derived class
body: <p><strong>In brief:</strong> From a C++ base-class pointer which points to an instance of a derived class, how can one determine at run-time whether a non-pure virtual function (with an implementation in the base class) has been re-implemented in the derived class?</p>
  
  <p><strong>The context:</strong> 
  I am writing a C++ library to solve certain classes of mathematical equation. The library provides an <code>Equation</code> class with several virtual functions, which library users use as a base class for the particular equation they wish to solve. The library also provides a <code>Solver</code> class, which takes an <code>Equation *</code> as a constructor parameter. The user then writes code along the lines of:</p>
  
  <pre><code>class MyEquation : public Equation
  { ... } // equation definition here
  
  int main()
  {
    MyEquation myEqn;
    Solver solver(&amp;myEqn);
    solver.Solve();
  }
  </code></pre>
  
  <p>If certain combinations of the virtual functions in <code>Equation</code> are not redefined in the derived equation class, certain computationally expensive parts of the algorithm run by the <code>Solver</code> object can be omitted. I would therefore like to know, in the constructor of <code>Solver</code>, which functions have been redefined, and which will instead run the default implementation in <code>Equation</code>.</p>
  
  <ul>
  <li><p>I would like to make this transparent to users of the library so I am not looking for a solution where, for example, the user sets some flags in the constructor of their derived equation specifying which functions have been redefined. </p></li>
  <li><p>One possible solution is for the default implementations of the virtual functions in <code>Equation</code> to set a private flag in the <code>Equation</code> class; the constructor of the <code>Solver</code> class can then clear this flag, run the virtual function, and check the flag value to see whether the implementation in <code>Equation</code> has been called. I would like to avoid this though, because simply setting the flag every time the virtual function is executed slows the algorithm down a good deal (the execution of these virtual functions contributes significantly to the run time of the program, and the default implementations simply return a constant).</p></li>
  </ul>