title: Using enum members to templatise member functions
body: <p>I am writing a class which can be instantiated in different modes. A simple case maybe
  a meancomputer which can compute different types of means based on the mode.</p>
  
  <p>The class will be instantiated by some other piece of code, and the class code will be generic through function pointers. The specific functions associated with different modes have to be defined and pointers set as per the mode.</p>
  
  <p>What i have looks like this</p>
  
  <pre><code>    enum StatMode { EMA, SMA} ;
  
      class MeanComputer {
      public:
          MeanComputer ();
          MeanComputer (const MeanComputer&amp; orig);
          virtual ~MeanComputer();
          template &lt;StatMode&gt; double Update (double x);
          template &lt;StatMode&gt; double Sample (double x);
          void Reset();
          void setFunction() { 
              if (mode == EMA ) do_calc = /*EMA mode function*/ ;
          }  
          double (MeanComputer::*do_calc)(double);
  
      private:
          std::vector &lt;double&gt; window ;
          double mean ;
          double variance ;
          StatMode mode;
      };
  
      template &lt;StatMode SMA&gt; double MeanComputer::Update(double x) {
      }
  
  
      template &lt;StatMode EMA&gt; double MeanComputer::Update(double x) {
      }
  </code></pre>
  
  <p>However this doesnt seem to compile and gives error
  error: no matching function for call to 'MeanComputer::Update(double&amp;)'</p>
  
  <p>How do I make this work.
  I understand one way is to have each such mode function defined by different names, and set 
  the function pointer then. Though that seems to require too much naming, and having cleaner mode template functions seem to be more elegant and easier to understand.</p>
  
  <p>UPDATE:
  The method of calculating is not set at compile time, but at runtime. however for a given object of the class the mode remains the same, so setting the pointers accordingly will do it once and for all.
  Also virtual base class also works, but in the actual case a lot of computation is generic,
  and only some specific or small functions depend on mode. A contrived example maybe the meancomputer takes the update of some kind of coordinate object, and it takes a pair of mode types, the SMA/EMA and latitude/longitude. So one instance maybe a a longitude mean while other is a latitude mean. The full computation is same , just one reads the different member.</p>