#include <stdlib.h>
#include <stdio.h>
#include<iostream>
using namespace std;
//函数模板
template<class T>
T abc(T& a, T& b, T& c)
{
return a + b*c;
}
template<class Ta,class Tb,class Tc>
Ta abc1(Ta& a, Tb& b, Tc& c)
{
return a + b*c;
}
//函数模板的调用 abc<int>(a, b, c)
void main()
{
int a = 10, c = 1, b = 10;
float b1 = 10.2;
cout << abc<int>(a, b, c) << endl;
cout << abc1<int, float, int>(a, b1, c) << endl;
system("pause");
}
void swap(int &x, int &y)
{
int temp = x;
x = y;
y = temp;
}
void main1()
{
int a = 1, b = 2;
swap(a, b);
cout << a << " "<< b << endl;
system("pause");
}
模板函数
最新推荐文章于 2020-09-23 20:52:07 发布