home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progc / fixed300.arj / BUG34.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-28  |  814 b   |  60 lines

  1. #if 0
  2. From:
  3. Subject: A failure of temporary destructors to be called
  4. Status: Fixed in ZTC++ 2.2
  5. #endif
  6.  
  7. //_ bug34.cpp
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11.  
  12. struct myClass
  13. {
  14.     myClass(char*);
  15.     ~myClass();
  16.     int sernum;
  17.     static int snc;
  18. };
  19.  
  20. myClass::sernum=0;
  21.  
  22. myClass::myClass(char* pc)
  23. {
  24.     sernum = ++snc;
  25.     printf("Constructing %d...\n",sernum);
  26. }
  27.  
  28. myClass::~myClass()
  29. {
  30.     snc--;
  31.     printf("Destroying %d...\n",sernum);
  32. }
  33.  
  34. int countDown(myClass & x)
  35. {
  36.     static int i = 5;
  37.     printf("countDown %d...\n",i--);
  38.     return (i);
  39. }
  40.  
  41. void main()
  42. {
  43.     while( countDown("xyz"))
  44.         ;
  45. }
  46.  
  47. /* OUTPUT:
  48. Constructing 1...
  49. countDown5...
  50. Constructing 2...
  51. countDown4...
  52. Constructing 3...
  53. countDown3...
  54. Constructing 4...
  55. countDown2...
  56. Constructing 5...
  57. countDown1...
  58. Destroying 5...
  59. */
  60.