模板函数

template < typename T >//或者class关键字
void Swap(T& a, T& b)
{
    T c = a;
    a = b;
    b = c;
}

隐式调用:

int a =0;

int b=1;

Swap(a,b);

显示调用:

int a=0;

int b=1;

Swap<int>(a,b);

 

 

也可以多类型的

template<class A,class B,class C>
A fun(B b,C c)
{
     reutrn b+c;
}


int a = fun<int,float,double>(1.0+2.00000000000)

 

posted @ 2019-01-06 22:22  朱小勇  阅读(231)  评论(0编辑  收藏  举报