tongqingliu

保持学习的态度

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);
}

posted on 2020-08-15 14:27  tongqingliu  阅读(113)  评论(0编辑  收藏  举报

导航