Monday, 1 December 2014

Example of constructor and destructor

#include<iostream>

using namespace std;

class abc
{
    public:
    abc()
    {
        cout<<"\nObject created \n";   
    }
    ~abc()
    {
        cout<<"\nObject deleted\n";
    }
};

main()
{
    cout<<"\nBlock 1\n";
    abc a1;   
    {
        cout<<"\nBlock 2\n";
        abc a2,a3;
    }
    cout<<"\nStarting of Block 3\n";
    {
        cout<<"\nBlock 3\n";       
        abc a6;       
    }
}

No comments:

Post a Comment