|
#include <iostream>
#include <cstdio>
using namespace std;

template <typename T1 , typename T2>
 T2 fun(T1 x,T2 y) {
T2 tmp = x *x + y * y + x * y;
return tmp;
}
 int main() {
int x1 = 1, y1 = 4;
float x2 = 1.1 , y2 = 2.2;
double x3 = 2.0 , y3 = 3.1;
cout << fun(x1, y1) << endl;
cout << fun(x2, y2) << endl;
cout << fun(x3, y3) << endl;
cout << fun(x1, y2) << endl;
return 0;
}

  1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 5 template <typename T> 6 T fun(T x,T y) { 7 T tmp = x *x + y * y + x * y; 8 return tmp; 9 } 10 int main() { 11 int x1 = 1,y1 = 4; 12 float x2 = 1.1 , y2 = 2.2; 13 double x3 = 2.0 , y3 = 3.1; 14 cout << fun(x1, y1) << endl; 15 //cout << fun(x1, y2) << endl; 16 cout << fun(x2, y2) << endl; 17 cout << fun(x3, y3) <<endl; 18 return 0; 19 } 20
|