模板函数

来源:互联网 发布:观山湖区经济发展数据 编辑:程序博客网 时间:2024/05/21 16:43
#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");}
0 0
原创粉丝点击