编程语言
首页 > 编程语言> > C++函数模板

C++函数模板

作者:互联网

#include<iostream>
using namespace std;

template <class T>
void printArray(const T *array, int count) {
    for (int i=0; i< count; i++) {
        cout << array[i] << " ";
    }
    cout << endl;
}

int main() {
    const int A_COUNT = 5, B_COUNT = 6, C_COUNT = 7;
    int a[A_COUNT] = {1, 2, 3, 4, 5};
    double b[B_COUNT] = {1.1, 2.2, 3.3, 4.4, 5.5 ,6.6};
    char c[C_COUNT] = "abcdef";

    printArray(a, A_COUNT);
    printArray(b, B_COUNT);
    printArray(c, C_COUNT);
}

标签:count,std,const,函数,printArray,int,void,C++,模板
来源: https://www.cnblogs.com/liutongqing/p/13508647.html