继承(Inheritance)
来源:互联网 发布:取消数据流量套餐 编辑:程序博客网 时间:2024/06/05 08:43
当代的面向对象语言(object-oriented, OO )为提高代码的设计,结构和可重用性,提供了封装(encapsulation),继承(inheritance)和多态(polymorphism). 今天,我们来看看继承在C++中的使用。
雇员的例子
以下是几种不同类型的雇员
- 普通员工
- 项目经理
- 总监
雇员类
.h
class employee{public: employee(string name, float payrate); string get_name() const; float get_payrate() const; float pay(float hours_worked) const;protected: string name; float payrate;};
.cc
employee::employee(string name, float payrate){this->this->name = name;this->this->payrate = payrate;}string employee::get_name() const{return name;}float employee::get_payrate() const{return payrate;}float employee::pay(float hours_worked) const{return hours_worked * payrate;}
Employee empl("John Burke", 25.0);输出为:
// Print out name and pay (based on 40 hours work).cout << "Name: " << empl.get_name() << endl;cout << "Pay: " << empl.pay(40.0) << endl;
Multiple Types of the Same Thing
在现实世界中,我们并不是把所有事物都看作是独一无二的,有时,我们把一些事物与另一些事物看作十分相似,除了一些小差异。
0 0
- 继承(Inheritance)
- 继承(inheritance)语法
- 继承(Inheritance)
- Swift 继承(Inheritance)
- inheritance anomaly(继承反常)
- 继承 Inheritance
- inheritance(继承)
- Inheritance(继承)
- Inheritance继承
- Inheritance继承
- 继承(inheritance)与组合(composition)
- 谨慎使用 multiple inheritance(多继承)
- C++重要性质02:继承(Inheritance)
- 对照Java学习Swift--继承(Inheritance)
- 区分 inheritance of interface(接口继承)和 inheritance of implementation(实现继承)
- 设计模式:Interface Inheritance (接口继承)和 Implementation Inheritance(实现继承)
- Java的Inheritance继承-笔记(面向对象2-继承)
- 继承映射(Inheritance Mappings)
- 两年半的工作总结
- VxWorks资料
- 安卓第二次实验单:openGL资料查阅
- spring mvc 下的mysql+mybatis批量更新
- Java性能调优工具
- 继承(Inheritance)
- 初探Java NIO
- c++中的.hpp文件
- 展示一下香蕉派路由Android系统
- stm32对nrf24l01无法操作
- 嵌入式 Ubuntu下设置VPN连接
- 算法学习笔记(八) 动态规划的一般求解方法
- 完整详解GCD系列(一)dispatch_async;dispatch_sync;dispatch_async_f;dispatch_sync_f
- Leetcode: Longest Substring Without Repeating Characters