c++的函数模板的省略...(用来实现一个连续打印的功能)

直接上代码:

#include<iostream>
#include<string.h>
#include<vector>
#include<unordered_set>
using namespace std;

template<class T>//单个函数参数的print
void print(const T& t){
    cout<<t<<endl;
}

template<class T,typename...N>//一定要注意写上面的一个函数,因为这个递归到了最后的时候是需要一个参数的也就不满足print的多个参数的编译
//多以一定要写一个只含一个的模板函数print用来处理最后一次的递归
void print(const T& t,const N& ...n){
    cout<<t<<endl;
    print(n...);
}
int main(int argc, char const *argv[])
{
    print(4,'k',"djajda",true);
    system("pause");
    return 0;
}

posted @ 2023-03-08 10:51  铜锣湾陈昊男  阅读(13)  评论(0)    收藏  举报