C++可变参数列表

#include 

using namespace std;

//停止解析参数列表
void function()
{

}

template 
void function(T t, U... args)
{
	//解析包的大小
	cout << "the numbers of args is " << sizeof...(U) + 1  << ends;
	//cout << "the size of args is " << sizeof...(args) + 1 << ends;

	cout << t << endl;
	function(args...);
}
int main()
{
	function("123", "456", "789", "10 11", "12 13");
	system("pause");
}
//结果
//the numbers of args is 5 123
//the numbers of args is 4 456
//the numbers of args is 3 789
//the numbers of args is 2 10 11
//the numbers of args is 1 12 13
//请按任意键继续. . .

 

你可能感兴趣的:(C++的各类函数)