C++11 两种新的数组形参使用方式

来源:互联网 发布:c语言基础代码 编辑:程序博客网 时间:2024/06/06 07:10

①使用标准库规范

void print(const int *beg, const int * end){    while (beg != end)        cout << *beg++ << endl;}//useint j[2] = {0, 1};print(begin(j), end(j));


②模板+数组引用形参

template <unsigned N>void print(const int (&arr)[N] ){    for (auto elem : arr)        cout << elem << endl;}//useprint (j);
print ("hello");


0 0
原创粉丝点击