C++ 定义和使用可变参数函数

 1 #include<iostream>
 2 using namespace std;
 3 void PrintAll(int n,...){
 4     int *ptr;
 5     ptr = &n;
 6     while(*ptr){
 7         cout<<*ptr<<endl;
 8         ptr++;
 9     }
10 }
11 int main(){
12     PrintAll(3,4,5,0);
13 }
14 输出:
15 3
16 4
17 5

1、可变参数函数的函数头书写形式:type func_name(para_type para1,...);

2、确定函数可变参数的实际个数和各个参数的实际类型.(只能从逻辑上做某些约定)

原文地址:https://www.cnblogs.com/teng-IT/p/6015147.html