qfedu-cpp-level/day6/homework/h1.cpp

21 lines
398 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 编写一个模板函数 maxValue接受两个参数并返回其中较大的值。
// 【提示】T maxVal(T &v1, T &v2)
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
template <typename T>
T maxVal(T &v1, T &v2)
{
return v1 > v2 ? v1 : v2;
}
int main()
{
int a = 2, b = 5;
cout << "更大的值是: " << maxVal(a, b) << endl;
return 0;
}