title: C++ cannot convert 'classname<int>' to 'int' in return
body: <p>I'm trying to apply template into the original class program. But I got the error of cannot covert 'Move' to 'int' in return. Please help....</p>
  
  <p>This is the template. The error is on line 40</p>
  
  <pre><code>#ifndef MOVE0_H_  
  #define MOVE0_H_
  template &lt;typename Type&gt;
  
  class Move
  {
      private:
          double x;
          double y;
      public:
          Move(double a = 0, double b = 0); // sets x, y to a, b
          void showmove() const; // shows current x, y values
          int add(const Move &amp; m) const;
          // this function adds x of m to x of invoking object to get new x,
          // adds y of m to y of invoking object to get new y, creates a new
          // move object initialized to new x, y values and returns it
          void reset(double a = 0, double b = 0); // resets x,y to a, b
  };
  
  template&lt;typename Type&gt;
  Move&lt;Type&gt;::Move(double a, double b)
  {
      x = a;
      y = b;
  }
  
  template&lt;typename Type&gt;
  void Move&lt;Type&gt;::showmove() const
  {
      std::cout &lt;&lt; "x = " &lt;&lt; x &lt;&lt; ", y = " &lt;&lt; y;
  }
  
  template&lt;typename Type&gt; 
  int Move&lt;Type&gt;::add(const Move &amp;m) const
  {
      Move temp;
      temp.x = x + m.x;
      temp.y = y + m.y;
  
      return temp;
  }
  
  template&lt;typename Type&gt;
  void Move&lt;Type&gt;::reset(double a, double b)
  {
      x = 0;
      y = 0;
  }
  #endif
  </code></pre>
  
  <p>Below is the main program, the program is at line 23</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include "move0.h"
  
  int main()
  {
      using namespace std;
      Move&lt;int&gt; origin, obj(0, 0);
      int temp;
      char ans='y';
      int x, y;
  
      cout&lt;&lt;"Origianl point: ";
      origin.reset(1,1);
      origin.showmove();
      cout&lt;&lt;endl;
      while ((ans!='q') and (ans!='Q'))
      {
            cout&lt;&lt;"Please enter the value to move x: ";
            cin&gt;&gt;x;
            cout&lt;&lt;"Please enter the value to move y: ";
            cin&gt;&gt;y; 
            obj= obj.add(temp);
            obj.showmove();
            cout&lt;&lt;endl;
            cout&lt;&lt;"Do you want to continue? (q to quit, r to reset): ";
            cin&gt;&gt;ans;
            if ((ans=='r') or (ans=='R'))
               {
               obj.reset(0, 0);
               cout&lt;&lt;"Reset to origin: ";
               obj.showmove();
               cout&lt;&lt;endl;
               }
      }
  
      return 0;
  }
  </code></pre>