带参数的构造函数及使用默认参数的构造函数
来源:互联网 发布:java 将图片写入word 编辑:程序博客网 时间:2024/05/17 22:51
带参数的构造函数:
#include<iostream>using namespace std;class Box{ public: Box(int h=10,int w=10,int l=10);//使用有参的构造函数对类中数据初始化,即设定默认值 int volume(); private: int height; int width; int length;};Box::Box(int h,int w,int l){ height=h; width=w; length=l;}int Box::volume(){ return (height*width*length);}int main(){ Box box1;//无参对象对应无参构造函数 ,数据使用默认值 cout<<"the volume1 is "<<box1.volume()<<endl; Box box2(12); cout<<"the volume2 is "<<box2.volume()<<endl; Box box3(12,23); cout<<"the volume3 is "<<box3.volume()<<endl; Box box4(12,23,34); cout<<"the volume4 is "<<box4.volume()<<endl; system("pause"); return 0;}使用默认参数的构造函数:
#include<iostream>using namespace std;class Box{ public: Box(int h,int w,int l); int volume(); private: int height; int width; int length;};Box::Box(int h,int w,int l){ height=h; width=w; length=l;}int Box::volume(){ return (height*width*length);}int main(){ Box box1(12,23,34);//此处使用构造函数,有参对象,对应有参构造函数 cout<<"the new volume is "<<box1.volume()<<endl; system("pause"); return 0;}
- 带参数的构造函数及使用默认参数的构造函数
- 带默认参数的构造函数
- C++使用带默认参数的构造函数
- 使用默认参数的构造函数
- 使用默认参数的构造函数
- C++使用默认参数的构造函数
- 使用默认参数的构造函数
- 默认参数的构造函数
- 默认参数的构造函数
- 默认参数的构造函数
- 三角形类的构造函数-使用带参数构造函数
- 带参数的构造函数
- 带参数的构造函数
- 带参数的构造函数
- 带参数的构造函数
- C++语言基础 例程 带默认参数的构造函数
- c++默认的构造函数中调用带参数的构造函数
- 第五周任务一之默认构造函数和带参数的构造函数
- Android中实现程序前后台切换效果。
- Android v22.0.1+ 关联 libs/*.jar 源码包的方法
- 利用itoa实现10进制数到2进制数的转换
- 我开通我都CSDN博客了
- 线程的分离与结合
- 带参数的构造函数及使用默认参数的构造函数
- window.print的应用
- DRP总结
- Remote java Application 远程调试
- Shell编程中if的语法和常见判断用法
- KMP算法
- oracle的数据文件全部丢失,但有归档和重做日志,如何恢复?
- 兼容FF,IE,Chrome的js离开或刷新页面检测
- tcp_tw_recycle和tcp_timestamps导致connect失败问题