Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- ////////
- // Двунапралвенная связь через публичные методы Ядра
- // задача - запуск метода ядра через Компонет, где метод ядра использует Другой компонент
- ////
- struct CCore_Base
- {
- virtual void getNum_Iv() = 0;
- virtual void getNum_Ren() = 0;
- };
- struct CComponent
- {
- CCore_Base* ptr_Core;
- void set_Core(CCore_Base* ptCr)
- {
- ptr_Core = ptCr;
- };
- };
- struct CIvent : CComponent
- {
- int num;
- CIvent(){ num = 5; }
- };
- struct CRender : CComponent
- {
- int num;
- CRender(){ num = 9; }
- };
- struct CCore : CCore_Base
- {
- CIvent cIv;
- CRender cRn;
- CCore()
- {
- cIv.set_Core( (CCore_Base*)this );
- cRn.set_Core( (CCore_Base*)this );
- }
- void getNum_Iv()
- {
- cout << "Number CIvent: " << cIv.num << endl;
- }
- void getNum_Ren()
- {
- cout << "Number CRender: " << cRn.num << endl;
- }
- };
- void main()
- {
- CCore cr;
- CIvent* ptCiv = & cr.cIv;
- CRender* ptCren = & cr.cRn;
- cout << "Get CRender number from CIvent" << endl;
- ptCiv->ptr_Core->getNum_Ren();
- cout << endl;
- cout << "Get CIvent number from CRender" << endl;
- ptCren->ptr_Core->getNum_Iv();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement