练习记录
来源:互联网 发布:澳门网络博客有限公司 编辑:程序博客网 时间:2024/06/01 07:32
依旧是慕课网的课后作业,觉得当笔记挺好,记录
#include <iostream>#include <stdlib.h>#include <string>using namespace std;/** * 定义工人类: Worker * 数据成员: m_strName * 成员函数: work() */class Worker{public: Worker(string name) { m_strName = name; cout << "Worker" << endl; } virtual ~Worker() { cout << "~Worker" << endl; } void work() { cout << m_strName << endl; cout << "work" << endl; }protected: string m_strName;};/** * 定义儿童类: Children * 数据成员: m_iAge * 成员函数: play() */class Children{public: Children(int age) { m_iAge = age; cout << "Children" << endl; } virtual ~Children() { cout << "~Children" << endl; } void play() { cout << m_iAge << endl; cout << "play" << endl; }protected: int m_iAge;};/** * 定义童工类: ChildLabourer * 公有继承工人类和儿童类 */class ChildLabourer : public Worker,public Children{public: ChildLabourer(string name, int age):Worker(name),Children(age) { cout << "ChildLabourer" << endl; } ~ChildLabourer() { cout << "~ChildLabourer" << endl; } };int main(void){ // 使用new关键字创建童工类对象 ChildLabourer *p = new ChildLabourer("Tim",13); // 通过童工对象调用父类的work()和play()方法 p->work(); p->play(); // 释放 delete p; p = NULL; return 0;}
阅读全文
0 0
- 练习记录
- (记录)练习的记录
- 缓冲区溢出练习记录
- POJ Volume1练习记录
- Linux练习记录
- openstack 练习记录
- shiny--练习记录
- SQL Server2005练习记录
- Kotlin项目练习记录
- 代码练习记录
- c++编程练习记录
- Python连接SqlServer练习记录
- Python连接SqlServer练习记录
- php练习9-11记录
- 第七周习题练习记录
- 我的算法练习记录
- Android简单ListView练习记录
- 蓝桥杯学习记录-基础练习
- 机器学习scikit-learn入门教程
- 常用函数
- 文件操作之fprintf函数的使用
- ios 绘制三角形
- webservice知识一、SOAP风格的webservice——通过JDK的API发布一个webservice服务和创建一个webservice客户端用于访问该服务
- 练习记录
- Android通知SD卡(内置/外置)扫描新数据
- 深入理解NaN
- [JZOJ5187]【NOIP2017提高组模拟6.30】tty's maze
- 如何在Ubuntu上安装最新版本的Node.js
- 解决了java+matlab混编+web(jsp)调用Matlab,网页中显示Figure,详细实例
- 获取当前句柄的4种方法
- java 线程间的状态转换
- Python格式化输出