C++11 STL Template特性

自C++11起,template可拥有那种“可以接收个数不定之template实参”的参数。此能力称variaddic template

#include <iostream>
#include <bitset>
void print(){

}
template<typename T,typename... Types>
void print(const T& arg1,const Types&... args){
    cout<<"arg1: "<<arg1<<"\t size of args="<<sizeof... (args)<<endl;
    print(args...);
}

int main()
{
    print(7.5,"hello",bitset<16>(378),42);
    return 0;
}

 

posted @ 2020-05-08 22:29  啸傲风月  阅读(298)  评论(0编辑  收藏  举报