Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- class DelegateClass {
- public:
- void print();
- };
- void DelegateClass::print() {
- cout << __func__ << endl;
- }
- template<class DT>
- class Main {
- private:
- void (DT::*_delegateFunction)();
- DT* _delegateInstance;
- public:
- void connectToDelegate(DT*, void (DT::*)());
- void run();
- };
- template<class DT>
- void Main<DT>::run() {
- (_delegateInstance->*_delegateFunction)();
- }
- template<class DT>
- void Main<DT>::connectToDelegate(DT* delegateInstance,
- void (DT::*delegateFunction)())
- {
- _delegateFunction = delegateFunction;
- _delegateInstance = delegateInstance;
- }
- int main() {
- DelegateClass d;
- Main<DelegateClass> c;
- c.connectToDelegate(&d, &DelegateClass::print);
- c.run();
- }
Advertisement
Add Comment
Please, Sign In to add comment