首页 > 其他 > 详细

使用默认参数的构造函数 .

时间:2016-06-19 18:30:15      阅读:186      评论:0      收藏:0      [点我收藏+]
 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<math.h>
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<queue>
 7 #include<vector>
 8 #include<set>
 9 #include<stack>
10 #include<string>
11 #include<sstream>
12 #include<map>
13 #include<cctype>
14 #include<limits.h>
15 using namespace std;
16 class box
17 {
18 public:
19     box(int h=10,int w=10,int len=10);  //  在声明函数的时候 指定默认参数 . 
20     int volume();
21 private:
22     int height,width,length;
23 };
24 box::box(int h,int w,int len)
25 {
26     height=h,width=w,length=len;
27 }
28 int box::volume()
29 {
30     return height*width*length;
31 }
32 int main()
33 {
34     box box1(5);   //   随意给定 0-3个实参  实参按照顺序对应  给定
35     printf("%d\n",box1.volume());
36 }

 

使用默认参数的构造函数 .

原文:http://www.cnblogs.com/A-FM/p/5598466.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!