组合和继承综合(9)

网友投稿 630 2022-11-18

组合和继承综合(9)

组合和继承综合(9)

#ifndef#define#include using namespace std;class display {public: display(); ~display(); void DoDisPlay();};#endif

#include "display.h"display::display() { cout << "display::display()" << endl;}display::~display() { cout << "display::~display()" << endl;}void display::DoDisPlay() { cout << "display::DoDisPlay()" << endl;}

#ifndef#define#include using namespace std;class key{public: key(); ~key(); void DoKey();};#endif

#include "Key.h"key::key() { cout << "key()" << endl;}key::~key() { cout << "~key()" << endl;}void key::DoKey() { cout << "key::DoKey()" << endl;}

#ifndef#define#include using namespace std;class mouse {public: mouse(); ~mouse(); void DoMouse();};#endif

#include "mouse.h"mouse::mouse() { cout << "mouse::mouse()" << endl;}mouse::~mouse() { cout << "mouse::~mouse()" << endl;}void mouse::DoMouse() { cout << "mouse::DoMouse()" << endl;}

#ifndef#define#include using namespace std;class print {public: print(); ~print(); void DoPrint();};#endif

#include "print.h"print::print() { cout << "print::print()" << endl;}print::~print() { cout << "print::~print()" << endl;}void print::DoPrint() { cout << "print::DoPrint()" << endl;}

#ifndef#define#include #include "print.h"#include "display.h"#include "Key.h"#include "mouse.h"using namespace std;//电脑继承display, key(我们这只是为了练习将显示和键盘用在了继承,一般显示和键盘也放到组合)class computer :public display, public key {public: int x; computer(); ~computer(); void DoCpu(); //电脑组合鼠标和打印机 mouse Mouse; print Print; };#endif

#include "computer.h"#include "display.h"#include "Key.h"#include "mouse.h"#include "print.h"//派生出来的protect通过初始化列表进行初始化,我们这都是public可以不通过初始化列表初始化computer::computer() :display(), key(), Mouse(),Print(),x(5){ cout << "computer::computer()" << endl;}computer::~computer() { cout << "computer:~:computer()" << endl;}void computer::DoCpu() { cout << "computer::DoCpu() " << endl;}

#include "computer.h"#include "print.h"#include "display.h"#include "Key.h"#include "mouse.h"int main() { computer Computer; Computer.DoCpu(); Computer.DoDisPlay(); Computer.DoKey(); Computer.Mouse.DoMouse(); Computer.Print.DoPrint(); return 0;}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:shell编程提高
下一篇:上拉电阻与下拉电阻
相关文章

 发表评论

暂时没有评论,来抢沙发吧~