【c++程序】向基类构造函数传递参数
来源:互联网 发布:spark sql java 实现 编辑:程序博客网 时间:2024/05/19 14:54
#include<iostream>#include<string>using namespace std;class father{protected:string name;int tall;public:father(string a,int i);father(){cout<<"构造基类"<<endl;}void print(){cout<<name<<"身高为:"<<tall<<endl;}~father(){cout<<"释放基类对象"<<endl;}};father::father(string a,int i){cout<<"\n 在基类构造函数\n";name=a;tall=i;print();cout<<"离开基类构造函数"<<endl;}class son:public father{private:int weight;public:son(string a,int i,int j);void print1();~son(){cout<<"\n释放子类对象\n";}};son::son(string a,int i,int j):father(a,i){weight=j;cout<<"\n在子类的构造函数内"<<endl;}void son::print1(){father::print();cout<<"体重:"<<weight;}int main(){son Mike("Mike",180,80);Mike.print1();cout<<"程序结束!"<<endl;return 0;} /*如果派生类要向基类传递参数,那么必须在派生类定义一个构造函数, 该函数只起到向基类传递参数的作用*/
0 0
- 【c++程序】向基类构造函数传递参数
- 向基类构造函数传递参数
- 向基类构造函数传递参数
- C++学习 向基类构造函数传递参数
- 向基类构造函数传递参数的(两种方法)
- (未完成)C++ 向基类的构造函数传递参数
- 向C语言程序传递命令行参数
- 如何在子类中向父类的构造函数传递参数
- [反射类] -- PHP动态实例化对象并向构造函数传递参数
- 构造函数传递参数
- 向程序传递命令行参数
- C/C++ 之 关于空类的大小与构造函数参数传递
- PHP面向对象——实例化对象时向构造函数传递参数
- C函数参数传递
- C函数参数传递
- 如何向基类传递参数
- MapReduce向Map函数传递参数: Configuration类
- MapReduce向Map函数传递参数: Configuration类
- POI读取Excel(兼容Excel2003、Excel2007)
- 蚊子132微信二次开发的模块
- animation的使用
- iOS 时间选择器
- Android中Sharedpreference的使用,记住登录后记住用户名密码
- 【c++程序】向基类构造函数传递参数
- test
- java子类赋值给父类
- MongoDB空口令检测
- JavaScript类型转换
- CI 系统搭建:五. GitLab、Gerrit、Jenkins 三者整合
- 【LeetCode】Substring with Concatenation of All Words 解题报告
- SQL FIRST() 函数
- OpenStack RBD 上传镜像非常慢