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:
- So sánh hệ thống tài khoản kế toán trong Thông tư 99/2025/TT-BTC và Thông tư 200/2014/TT-BTC
- Common Pitfalls in TOEIC Preparation and How Strategic Learning Improves Test Performance
- Singapore’s First Multi-Storey 3D-Printed House
- 3D Concrete printing Technology
- Giới thiệu 8 đặc điểm của High Performance Team

