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

C++11 STL Template特性

 

相关文章:

  • 2021-09-09
  • 2021-05-25
  • 2021-05-20
猜你喜欢
  • 2022-12-23
  • 2021-04-26
  • 2021-10-18
  • 2022-12-23
  • 2021-04-19
  • 2021-05-30
  • 2021-11-19
相关资源
相似解决方案