povray-derived.cc 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // { dg-do run }
  2. // Small test case from povray, see if it reproduces.
  3. #include <stdio.h>
  4. class POVMS_MessageReceiver
  5. {
  6. private:
  7. int x;
  8. class Handler
  9. {
  10. public:
  11. virtual void print() = 0;
  12. };
  13. protected:
  14. template<class T> class MemberHandler : public Handler
  15. {
  16. public:
  17. MemberHandler(T *xx)
  18. {
  19. x = xx;
  20. }
  21. ~MemberHandler() {}
  22. void print()
  23. {
  24. printf("In print\n");
  25. }
  26. private:
  27. T *x;
  28. };
  29. private:
  30. struct HandlerNode
  31. {
  32. Handler *handler;
  33. };
  34. HandlerNode *receiver;
  35. public:
  36. POVMS_MessageReceiver(int xx) : x(xx) {}
  37. ~POVMS_MessageReceiver() {}
  38. void foo(int *xx);
  39. void try_call();
  40. };
  41. void POVMS_MessageReceiver::foo(int *xx)
  42. {
  43. receiver = new HandlerNode;
  44. receiver->handler = new MemberHandler<int>(xx);
  45. }
  46. void POVMS_MessageReceiver::try_call()
  47. {
  48. receiver->handler->print();
  49. }
  50. int main()
  51. {
  52. int loc = 34;
  53. POVMS_MessageReceiver a_test(100);
  54. a_test.foo(&loc);
  55. a_test.try_call();
  56. }