码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-10-31 13:38:36      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:span   amp   color   cout   style   void   ...   r++   str   

 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、确定函数可变参数的实际个数和各个参数的实际类型.(只能从逻辑上做某些约定)

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

标签:span   amp   color   cout   style   void   ...   r++   str   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!