美文网首页
c++函数模板例子

c++函数模板例子

作者: 一路向后 | 来源:发表于2021-08-11 20:36 被阅读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

相关文章

网友评论

      本文标题:c++函数模板例子

      本文链接:https://www.haomeiwen.com/subject/ttchbltx.html