fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct IDelegate
  5. {
  6. ~IDelegate() {}
  7. virtual void UpdateDisplay(int) = 0;
  8. };
  9.  
  10. class Display
  11. {
  12. private:
  13. IDelegate* m_pDelegate;
  14. public:
  15. Display( IDelegate* pDelegate = NULL)
  16. : m_pDelegate( pDelegate )
  17. {
  18. }
  19.  
  20. void MyFunc(int iSel)
  21. {
  22. if(m_pDelegate)
  23. if(rand() & 1) //assume
  24. m_pDelegate->UpdateDisplay(iSel);
  25. }
  26. };
  27.  
  28. ///////
  29.  
  30. class PlaneDlg : public IDelegate
  31. {
  32. private:
  33. Display m_display;
  34. public:
  35. PlaneDlg () : m_display ( this )
  36. {
  37. }
  38.  
  39. void UpdateDisplay(int iGrp)
  40. {
  41. // do something..
  42. }
  43. };
  44.  
  45. int main() {
  46. // your code goes here
  47. return 0;
  48. }
Success #stdin #stdout 0s 3092KB
stdin
Standard input is empty
stdout
Standard output is empty