Cách viết Function templates và class templates
Cách viết Function templates và class templates
#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:
- Giới thiệu khoá học “APNIC’s Vulnerability Reporting Program” (APNIC Academy)
- CÁC CÔNG CỤ QUẢN LÝ LỖI PHẦN MỀM (SOFTWARE DEFECT MANAGEMENT TOOLS)
- How to Learn English Vocabulary Effectively
- Cách để học và ôn tập Reading của TOEIC hiệu quả
- KlimaKover: Công nghệ làm mát bức xạ và một hướng tiếp cận mới cho không gian đô thị

