模板和泛型编程???从P269继续
#include <iostream>using namespace std;#define COPY(A,B,N)\ {int i; \ for(i=0;i<(N);++i) (B)[i]=(A)[i];}template<class T>void printArr(T from[], int size){ for(int i=0;i<size;i++) cout<<from[i]<<"\t"; cout<<endl;}int main(void){ int a[10]={1,2,3,4,5,6,7,8,9,10},b[10]; double c[20]={10,9,8,7,6,5,4,3,2,1},d[20]; COPY(a,b,10); printArr(b,10); system("pause"); return 0;}?
二、使用模板
?
1. Template Class 模板类
2. Function Templates 函数模板
Many functions have the same code body, regardless of type(例如上面的例子)
?
?
?
?
?