c++函数模板例子
2021-08-11 本文已影响0人
一路向后
1.源码实现
#include <iostream>
#include <string>
#include <vector>
using namespace std;
template <typename T>
T const &Max(T const &a, T const &b)
{
return a < b ? b : a;
}
int main()
{
int i = 29;
int j = 51;
cout << Max(i, j) << endl;
return 0;
}
2.编译源码
$ g++ -o example example.cpp
3.运行及其结果
$ ./example
51