MaximCherchuk

More painful

Apr 8th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. class DelegateClass {
  6. public:
  7.     void print();
  8. };
  9.  
  10. void DelegateClass::print() {
  11.     cout << __func__ << endl;
  12. }
  13.  
  14. template<class DT>
  15. class Main {
  16. private:
  17.     void (DT::*_delegateFunction)();
  18.     DT* _delegateInstance;
  19. public:
  20.     void connectToDelegate(DT*, void (DT::*)());
  21.     void run();
  22. };
  23.  
  24. template<class DT>
  25. void Main<DT>::run() {
  26.     (_delegateInstance->*_delegateFunction)();
  27. }
  28.  
  29. template<class DT>
  30. void Main<DT>::connectToDelegate(DT* delegateInstance,
  31.         void (DT::*delegateFunction)())
  32. {
  33.     _delegateFunction = delegateFunction;
  34.     _delegateInstance = delegateInstance;
  35. }
  36.  
  37. int main() {
  38.     DelegateClass d;
  39.     Main<DelegateClass> c;
  40.     c.connectToDelegate(&d, &DelegateClass::print);
  41.     c.run();
  42. }
Advertisement
Add Comment
Please, Sign In to add comment