Cách sử dụng Function templates are similar to class templates
#include "stdafx.h"
#include <iostream>
using namespace std;
template <class T>
T Max(T a, T b)
{
return (a<b) ? b : a;
}
template <class T>
T Max(T a, T b, T c)
{
return max(a, max(b, c));
}
template <class T>
T Max(T a[], int n) {
T max = a[0];
for (int i = 1; i<n; i++)
max = Max(max, a[i]);
return max;
}
int main()
{
int a[] = { 2, 9, 8, 4 };
cout << Max(1, 2) << " " << Max(2.13, 1.21) << " " << Max(a, 4) << endl;
return 0;
}
Trương Đình Huy
Tin tức liên quan:
- Navigating Global Opportunities: An Introduction to the LanguageCert Test
- Terra Cotta Workshop: Xưởng gốm bên sông Thu Bồn giành chiến thắng tại RIBA International Awards for Excellence 2026
- Software Testing - Internationalization Testing & Documentation Testing (P1)
- Các thuật ngữ LLM quan trọng mà Developer nên biết
- Nhà hàng, quán cà phê đau đầu với bản quyền âm nhạc

