Guest User

Untitled

a guest
Jan 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. class Obsevers {
  2. public:
  3. virtual ~Obsevers() {}
  4. };
  5.  
  6. class TestObserver : public Obsevers {
  7. public:
  8. void print1(int i) {
  9. std::cout << i << std::endl;
  10. }
  11. };
  12.  
  13. class TestObserver2 : public Obsevers {
  14. public:
  15. void print2(int i, char c) {
  16. std::cout << i << " , " << c << std::endl;
  17. }
  18. //possible new functions here later
  19. };
  20.  
  21. template<typename Type, typename Notify>
  22. void NotifyObserver(Notify notify) {
  23. typedef std::list<Obsevers*>::iterator iter;
  24. iter it = m_observers.begin();
  25. iter end = m_observers.end();
  26. for(; it != end; ++it) {
  27. Type * o = dynamic_cast<Type*>(*it);
  28. if(o == NULL) continue;
  29. notify(o);
  30. }
  31. }
  32.  
  33. NotifyObserver<TestObserver2>(boost::bind(&TestObserver2::print2, _1, 32, 'b'));
Add Comment
Please, Sign In to add comment