使用默认参数的构造函数
参数 默认 构造函数 使用
2023-09-14 09:12:06 时间
1 #include <iostream> 2 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 4 using namespace std; 5 6 class Box 7 { 8 public: 9 Box(int h=10,int w=10,int len=10); 10 int volume(); 11 private: 12 int height; 13 int width; 14 int length; 15 }; 16 17 Box::Box(int h,int w,int len) 18 { 19 height=h; 20 width=w; 21 length=len; 22 } 23 24 int Box::volume() 25 { 26 return(height*width*length); 27 } 28 29 int main(int argc, char** argv) { 30 Box box1; 31 cout<<"The volume of box1 is"<<box1.volume()<<endl; 32 Box box2(15); 33 cout<<"The volume of box2 is"<<box2.volume()<<endl; 34 Box box3(15,30); 35 cout<<"The volume of box3 is"<<box3.volume()<<endl; 36 Box box4(15,30,20); 37 cout<<"The volume of box4 is"<<box4.volume()<<endl; 38 return 0; 39 }
相关文章
- HttpServletRequest修改/添加header和cookie参数
- SpringMVC 数组类型的参数: Cannot generate variable name for non-typed Collection parameter type
- 面试-默认参数(传值)、var(传址)、out(输出)、const(常数)
- python类中的self参数和cls参数
- 浏览器URL参数解决方案
- nls_timestamp_format参数在11.2中的变化
- Spring Aop 修改目标方法参数和返回值
- golang方法的使用细节:参数默认是值拷贝,不仅仅是struct自定义数据类型也可以绑定方法、方法名称首字母大写为public权限、String()方法的使用
- Hystrix配置参数查找方式
- 关于 SAP UI5 参数 $$updateGroupId 前面两个 $ 符号的含义
- SAP Spartacus 服务器端渲染的默认参数
- 天猫精灵语音技能单轮对话表达式的参数定义
- Atitit 理解参数 目录 1. 参数1 1.1. 意义1 1.2. 形式参数 实际参数1 1.3. 默认参数 vs 必须参数2 1.4. 位置参数,那么这个命名关键字参数2 1.5. I
- SpringBoot升级到2.0后默认时间格式变化_springboot接收date类型参数
- (2/8)枚举的错误用法 之 方法参数
- c++ 模板参数有默认值时模板特例化匹配问题
- C++使用默认参数的构造函数
- LCC编译器的源程序分析(17)参数变量的声明
- 修改Docker容器启动配置参数
- 信号完整性(SI)电源完整性(PI)学习笔记(二十七)S参数在信号完整性中的应用(二)
- 改进YOLOv7系列:25.YOLOv7 加入RepVGG模型结构,重参数化 极简架构