Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. /* Question Number: 6 Constructor and Destructors*/
  2. #include <iostream>
  3. #include <stdlib.h>
  4. using namespace std;
  5.  
  6. unsigned int created=0,destroyed=0;
  7. class Counter{
  8.     int c;
  9.     public:
  10.         Counter() : c(0)
  11.         {
  12.             created++;
  13.         }
  14.         ~Counter()
  15.         {
  16.             destroyed++;
  17.             created--;
  18.         }
  19.     void display(){
  20.         cout<<"\n The Number of objects created are : "<<created;
  21.         cout<<"\n Number of objects destroyed are : "<<destroyed;
  22.     }
  23. };
  24. void block1()
  25. {
  26.     cout<<"\n In Block 1 : \n";
  27.     Counter c1,c2,c3,c4;
  28.     c4.display();
  29. }
  30. void block2()
  31. {
  32.     cout<<"\n\n In Block 2 : \n";
  33.     Counter c1,c2;
  34.     c2.display();
  35. }
  36. void block3()
  37. {
  38.     cout<<"\n\n In Block 3 : \n";
  39.     Counter c;
  40.     c.display();
  41. }
  42.  
  43. int main()
  44. {
  45.     block1();
  46.     block2();
  47.     block3();
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement