//FunctionTemplate.cpp
#include <iostream>
#include <string>
using std::string;
using std::cout;
using std::cin;
using std::endl;
struct stu
{
string name;
double score;
};
template <typename T>
void swap(T& x,T& y);
template <typename T1,typename T2>
auto get(T1 x,T2 y) ->decltype(x+y);
stu& operator+(stu& s1,stu& s2);
int main()
{
int a=1,b=2;
double c=1.1,d=2.2;
stu s1={"fyj",100},s2={"jyf",90};
swap(a,b);
swap(c,d);
swap(s1,s2);
cout << a << "," << b << endl
<< c << "," << d << endl
<< s1.name << "," << s1.score << endl
<< s2.name << "," << s2.score << endl;
cout << get(a,c) << endl
<< get(b,d) << endl
<< (s1+s2).name << "," << (s1+s2).score << endl;
while(cin.get()!='\n');
return 0;
}
template <typename T>
void swap(T& x,T& y)
{
T temp=x;
x=y;
y=temp;
}
template <typename T1,typename T2>
auto get(T1 x,T2 y) ->decltype(x+y)
{
decltype(x+y) z=x+y;
return z;
}
stu& operator+(stu& s1,stu& s2)
{
s1.name="haha";
s1.score=s1.score+s2.score;
return s1;
}
FunctionTemplate
最新推荐文章于 2024-11-12 21:05:38 发布