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:
- The integration of Building Information Modeling (BIM) changing project planning and execution in the construction industry
- Giới thiệu khoá học “Mutually Agreed Norms for Routing Security (MANRS)” (APNIC Academy)
- Using AI for English Speaking Comprehension and Real-life
- Con đường giải mã suy nghĩ: từ ý niệm trong não đến chữ viết
- BẢO MẬT THÔNG TIN TRONG MẠNG TRUYỀN THÔNG KHÔNG DÂY

