正在加载图片...
第9章模板 例9.4模板函数的覆盖 Include <string. h> #include <iostream. h> template <class t> T max(T a, T b) return a>b?a: b char *max(char x, char*y return strcmp(x, y)>0?x void main(void) char *p=ABCD,*q=" EFGH"; p=max(p, g) int a=max (10, 20 float b=max(10.5, 20.6); 程序运行结果为 cout<<p≤≤endl; EFGH cout < a < end: cout≤≤b<<end; 20.6例9.4 模板函数的覆盖 #include <string.h> #include <iostream.h> template <class T> T max(T a, T b) { return a>b?a:b; } char *max(char *x, char *y) { return strcmp(x, y) > 0 ? x :y; } void main(void) { char *p="ABCD", *q="EFGH"; p=max(p, q); int a =max(10, 20); float b =max(10.5, 20.6); cout << p << endl; cout << a << endl; cout << b << endl; } 第9章 模板 程序运行结果为: EFGH 20 20.6
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有