variadic template(一)

使用可变参数模板重写print

 

#include<iostream>
#include<bitset>
using namespace std;
void printX()
{

}

template<typename T, typename... Types>
void printX(const T& firstArg, const Types&... args)
{
  sizeof...(args);  // get number of args cout
<< firstArg << endl; printX(args...); } int main() { printX(7.5, "hello", bitset<16>(377), 42); return 0; }

 

posted @ 2022-01-28 21:17  王清河  阅读(37)  评论(0编辑  收藏  举报