Program to illustrate Destructor


#include <iostream.h>
#include<conio.h>
int no_of_objects = 0;         // Global Declaration
class sample
{
    public:
        sample();
        ~sample();            // Destructor Declaration
};
sample::sample()
{
    no_of_objects++;
    cout << "No of object created  " << no_of_objects;
    cout << "\n";
}
sample::~sample()            // Destructor Definition
{
    cout << "No of object Destroyed " << no_of_objects;
    cout << "\n";
    no_of_objects--;
}
void main(void)
{       clrscr();

    void function();        // prototype
    cout << "\nMAIN Entered\n";
    sample s1, s2, s3;
    {
        cout << "\nBLOCK-1 Entered\n";
        sample s4, s5;
    }
    function();
    {
        cout << "\nBLOCK-2 Entered\n";
        sample s7;
    }
    cout << "\nMAIN Re-Entered\n";

    getch();
}
void function()
{
    cout << "\nFUNCTION Entered\n";
    sample s6;
}

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|