Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BaseWindow;
- class Button
- {
- public:
- Button(BaseWindow* parent)
- {
- parent->AddButton(this);
- }
- void SetBehavior(/*Owners pointer and owner's methos*/)
- {
- /* Save Owner pointer and owner's method*/
- }
- void Clicked(/*coords*/)
- {
- if(/*coords == my coords*/)
- {
- /*Call Owner's method*/
- }
- }
- };
- class BaseWindow
- {
- vector<Button*> Buttons;
- WindowClicked(/*coords*/)
- {
- for (std::vector<Button*>::iterator it = Buttons.begin(); it != Buttons.end(); ++it)
- {
- it->Clicked(/*coords*/);
- }
- }
- public:
- void AddButton(Button* butt)
- {
- Buttons<<butt;
- }
- };
- class UserWindow:public BaseWindow
- {
- Button MyButton;
- public:
- void FunctionForButton(Button* butt){ cout<<"Say Hello, my sweet button";}
- UserWindow():MyButton(this)
- {
- MyButton.SetBehavior(/*Put here my Function for Button and my pointer*/);
- }
- };
- typedef void (BaseWindow::*TBehavior)(Button *);
- (parent->*behavior)(this);
- MyButton.SetBehavior(static_cast<TBehavior>(&UserWindow::FunctionForButton));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement