c++中函数模板的用法。

2025-05-18 00:04:16
推荐回答(2个)
回答1:

代码如下:

#include 

using namespace std;

template
T Add(T a, T b)
{
return a + b;
}

int main()
{
cout << Add(3, 4) << endl;
cout << Add(3.4, 4.4) << endl;
system("pause");
return 0;
}

回答2:

在使用函数是必须要有
#include...〈stdio.h〉
#include〈math.h〉
{
然后是函数名();
}
这是手机大的可能格式有点问题,不过就是这种形式。