首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

模板跟泛型编程?从P269继续

2012-08-27 
模板和泛型编程???从P269继续#include iostreamusing namespace std#define COPY(A,B,N)\{int i \for(

模板和泛型编程???从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(例如上面的例子)

?

?

?

?

?

热点排行