title: Calling function template of class template in C++
body: <p>I have intermediate level of knowledge in C++ and I would like to beg your pardon if you find the question is very easy or not of standard to post in this blog. But, somehow I was unable to solve it.  :) </p>
  
  <p>Your kind help would be appreciated. Here is my code:
  The class template is following in a .hpp file:</p>
  
  <pre><code>template&lt;typename T&gt;
  class FastRetinexFilter{
  public:
  
      static T* getInstance();    
      T Adjust(cv::Mat source, cv::Mat &amp;destination, bool adjustBrightness=true, bool adjustColors=true, int n=3, bool filterOnlyIllumination=false, bool guidedFilter=false, double adjustmentExponent=1.0/2.0, int kernelSize=25, int finalFilterSize=5, double upperBound=255.0);
      ......
      ......
      ......
  
  private:
      .....
      ..... 
      static T *s_instance;
  };
  </code></pre>
  
  <p>The definition of the functions are following in a .cpp file</p>
  
  <pre><code>#include "FastRetinexFilter.hpp"
  
  using namespace cv;
  template &lt;class T&gt; T* FastRetinexFilter&lt;T&gt;::s_instance = 0;
  
  template &lt;class T&gt; T*
  FastRetinexFilter&lt;T&gt;:: getInstance() {
      if (!s_instance)
          s_instance = new FastRetinexFilter();
  
      return s_instance;
  }
  
  template &lt;class T&gt; T FastRetinexFilter&lt;T&gt;::Adjust(cv::Mat source, cv::Mat &amp;destination, bool adjustBrightness, bool adjustColors, int n, bool filterOnlyIllumination, bool guidedFilter, double adjustmentExponent, int kernelSize, int finalFilterSize, double upperBound){
  
      if (adjustBrightness==false &amp;&amp; adjustColors==false){
          source.copyTo(destination);
          return;
      }
  
      cv::Mat gray;
      cvtColor(source, gray, COLOR_BGR2GRAY);
      ......
      ......
  }    
  ......
  ......
  ...... 
  </code></pre>
  
  <p>Now, I would like to call the adjust function from another class, where I have included the header file and the member of FastRetinexFilter class is properly visible there. </p>
  
  <p>I tried to do it in this manner :</p>
  
  <pre><code>FastRetinexFilter::getInstance()-&gt;Adjust(colorImgMat, result, brightnessAdjustment, colorCorrection, n, false, gif, a);
  </code></pre>
  
  <p>But it is giving me error. It says that </p>
  
  <blockquote>
    <p>"FastRetinexFilter" is not a class, namespace, or enumeration</p>
  </blockquote>
  
  <p>please suggest how should I can call this function template by using the getInstance() method.</p>
  
  <p>When I don't use the template, the definition is like this. I do like this in other classes, which works fine :   </p>
  
  <pre><code>FastRetinexFilter* FastRetinexFilter::instance = 0;
  
      FastRetinexFilter* FastRetinexFilter::getInstance() {
          if (!instance)
              instance = new FastRetinexFilter();
  
          return instance;
      }
  
  
  In the header file the declaration is like this :
  
  public:
      static FastRetinexFilter* getInstance();
          ......
          .....
  private:
      static FastRetinexFilter* instance;
          ......
          ......
  </code></pre>
  
  <p>To call some function (e.g. connectedComponentLabeling) from this class, I do :</p>
  
  <pre><code>FastRetinexFilter::getInstance()-&gt;connectedComponentLabeling(binImageCopy,numComponent);
  </code></pre>
  
  <p>But I don't understand, how to do it in the case of templates. 
  The function "getInstance()" will return a object pointer of the class FastRetinexFilter. 
  So according to your answers, I should do like this :</p>
  
  <pre><code>FastRetinexFilter&lt;FastRetinexFilter*&gt;::getInstance()-&gt;Adjust(...);
  </code></pre>
  
  <p>But this does not work. 
  What should I try ? Please suggest. I need to use template for other functions in the this class. So, it is necessary to use class template and function template here. </p>