#include <iostream>
using namespace std;
template<typename T, typename U>
struct Pair{
T first;
U second;
Pair():first(T()),second(U())
{
}
Pair(const T&f, const U&s):first(f),second(s)
{
}
};
template<typename T, typename U>
void show(const Pair<T,U> p)
{
cout << p.first << ',' << p.second << endl;
}
template<typename T, typename U>
Pair<T,U> mkpair(T f, U s)
{
return Pair<T,U>(f,s);
}
int main()
{
Pair<int ,double> p1;
Pair<int, string> p2(100,"hello");
show(p1);
show(p2);
show(mkpair('c', 5));
show(Pair<char ,int>('c',5));
return 0;
}
模版实例化
最新推荐文章于 2021-05-21 14:00:00 发布