C++ cannot convert 'classname<int>' to 'int' in return -


i'm trying apply template original class program. got error of cannot covert 'move' 'int' in return. please help....

this template. error on line 40

#ifndef move0_h_   #define move0_h_ template <typename type>  class move {     private:         double x;         double y;     public:         move(double = 0, double b = 0); // sets x, y a, b         void showmove() const; // shows current x, y values         int add(const move & m) const;         // function adds x of m x of invoking object new x,         // adds y of m y of invoking object new y, creates new         // move object initialized new x, y values , returns         void reset(double = 0, double b = 0); // resets x,y a, b };  template<typename type> move<type>::move(double a, double b) {     x = a;     y = b; }  template<typename type> void move<type>::showmove() const {     std::cout << "x = " << x << ", y = " << y; }  template<typename type>  int move<type>::add(const move &m) const {     move temp;     temp.x = x + m.x;     temp.y = y + m.y;      return temp; }  template<typename type> void move<type>::reset(double a, double b) {     x = 0;     y = 0; } #endif 

below main program, program @ line 23

#include <iostream> #include <string> #include "move0.h"  int main() {     using namespace std;     move<int> origin, obj(0, 0);     int temp;     char ans='y';     int x, y;      cout<<"origianl point: ";     origin.reset(1,1);     origin.showmove();     cout<<endl;     while ((ans!='q') , (ans!='q'))     {           cout<<"please enter value move x: ";           cin>>x;           cout<<"please enter value move y: ";           cin>>y;            obj= obj.add(temp);           obj.showmove();           cout<<endl;           cout<<"do want continue? (q quit, r reset): ";           cin>>ans;           if ((ans=='r') or (ans=='r'))              {              obj.reset(0, 0);              cout<<"reset origin: ";              obj.showmove();              cout<<endl;              }     }      return 0; } 

your add member function returns int:

int add(const move & m) const; 

but returning move object:

template<typename type>  int move<type>::add(const move &m) const {     move temp;     ...     return temp; } 

there no conversion move int. seems want return move:

move add(const move & m) const; 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -