C++基类派生类
来源:互联网 发布:恢复出厂设置数据恢复 编辑:程序博客网 时间:2024/05/16 12:45
// C++_test1.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include<iostream>#include<string>#include<cctype>#include<fstream>// using namespace std;using std::cin;using std::cout;using std::endl;using std::string;using std::ifstream;//基类class BaseClass {public:BaseClass() {}void f(char*s = "unknown") {cout << "Function f() in BaseClass called from " << s << endl;h();}protected:void g(char*s = "unknown") {cout << "Function g() in BaseClass is called from " << s << endl;}private:void h() {cout << "Function h() in BaseClass\n";}};//派生类class Derived1Level1 :public virtual BaseClass {public:void f(char*s = "unknown") {cout << "Function f() in Derived1Level1 is called from " << s << endl;g("Derived1Level1");h("Derived1Level1");}void h(char*s = "unknown") {cout << "Function h() in Derived1Level1 is called from " << s << endl;}};//派生类class Derived2Level1 :public virtual BaseClass {public:void f(char*s = "unknown") {cout << "Function f() in Derived2Level1 is called from " << s << endl;g("Derived2Level1");}};class Derived2Level2 :public Derived1Level1, public Derived2Level1 {public:void f(char*s = "unknown") {cout << "Function f() in Derived2Level2 is called from " << s << endl;g("Derived2Level2");Derived1Level1::h("Derived2Level2");BaseClass::f("Derived2Level2");}};int main() {BaseClass bc;Derived1Level1 d1ll;Derived2Level1 d2ll;Derived2Level2 d22;bc.f("main(1)");d1ll.f("main(2)");d1ll.h("main(3)");d2ll.f("main(4)");d22.f("main(5)");d22.h();//暂停,供用户按下enter// system("pause");cin.ignore();return 0;}
0 0
- 继承---派生类(C++)
- [c++]派生类的应用
- 【C++】派生类构造函数
- [C++]继承和派生类
- C++: 类的继承派生
- 基类与派生
- 基类派生
- 派生和基类
- 基类与派生
- c++,派生类无法调用基类构造函数
- 【C++】派生类对象初始化基类的引用
- C++(29)基类和派生类
- c++primer plus第十三章-派生类与基类
- C++-继承:基类与派生类的关系
- [c++]派生类与容器类
- C语言类的继承和派生
- [c++]派生类的访问控制
- C++__类模板的派生
- Spark应用运行流程
- Enable VT-x in your BIOS 怎么解决
- C. Dishonest Sellers
- Ubuntu关于Hadoop2.7.x初步安装时,环境变量的设置
- Android操作数据库的框架-GreenDao基本使用记录
- C++基类派生类
- VS中调用DLL进行测试;vs进行远程调试;python中进行debug调试需要的文件
- WebGis实践(1)
- Zigbee网络架构+ZigBee的体系结构+理解zigbee节点的实现的案例+“51单片机” 和 “zigbee” 、 “cc2530芯片” 之间的关系+芯片cc2530
- 递推递归--I蟠桃记
- 萌新前端-Django学习之问题集(一)
- 线性表的顺序结构
- java swing tree 方式
- nyoj 677 碟战 (dfs)