函数模版

来源:互联网 发布:阿呆喵 知乎 编辑:程序博客网 时间:2024/05/01 14:03
#include <iostream>using namespace std;template <class T>//等价于template <typename T>void printArray(const T* tempArray,int count){for(int i=0;i<count;i++){cout << " " << tempArray[i];if((i+1)%15==0)cout << endl;}cout << endl;}int main(){const int ACOUNT = 5;const int BCOUNT = 6;const int CCOUNT = 7;int a[ACOUNT] = {2,3,4,5,6};double b[BCOUNT] = {1.2,2.3,3.4,4.5,5.6,6.7};char c[CCOUNT] = "Hello";cout << "array a contains :" << endl;printArray(a,ACOUNT);cout << "array b contains :" << endl;printArray(b,BCOUNT);cout << "array c contains :" << endl;printArray(c,CCOUNT);system("pause >> cout");return 0;}

0 0
原创粉丝点击