Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2011
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include "Poco/BasicEvent.h"
  2. #include "Poco/Delegate.h"
  3. #include <iostream>
  4.  
  5. using Poco::BasicEvent;
  6. using Poco::Delegate;
  7.  
  8. class Source
  9. {
  10. public:
  11.     BasicEvent<int> theEvent;
  12.  
  13.     void fireEvent(int n)
  14.     {
  15.         theEvent(this, n);
  16.     }
  17. };
  18.  
  19. class Target
  20. {
  21. public:
  22.     void onEvent(const void* pSender, int& arg)
  23.     {
  24.         std::cout << "onEvent: " << arg << std::endl;
  25.     }
  26. };
  27.  
  28. int main(int argc, char** argv)
  29. {
  30.     Source source;
  31.     Target target;
  32.  
  33.     source.theEvent += Delegate<Target, int>(
  34.         &target, &Target::onEvent);
  35.  
  36.     source.fireEvent(42);
  37.  
  38.     source.theEvent -= Delegate<Target, int>(
  39.         &target, &Target::onEvent);
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement