C++可变长参数va_list的使用

来源:互联网 发布:单片机驱动大功率led 编辑:程序博客网 时间:2024/06/05 15:15
#include <iostream>#include <string>#include <vector>#include <list>#include <cstdarg>template<typename T>static void Test(int va_list_len, ...) {  va_list arguments;  va_start(arguments, va_list_len);  for (int i = 0; i < va_list_len; ++i) {    T t = va_arg(arguments, T);    std::cout << t << std::endl;  }  va_end(arguments);}int main() {  Test<int>(3, 1, 2, 3);  Test<char>(3, 'a', 'b', 'c');  return 0;}

阅读全文
0 0