Get Email Subscription

Enter your email address:

Delivered by FeedBurner

Wednesday, April 21, 2010

This is a program to illustrate Constructors and Destructors. (C++)

#include< iostream.h>
#include< conio.h>
#include< stdlib.h>
#include< string.h>
#include< new.h>
class emp
{
char name[20];
int age;
float sal;
public:

void * operator new (size_t bytes);

void operator delete(void *k);
emp();
~emp();
};
char pool[sizeof(emp)];
emp::emp()
{ cout< < endl< < "Reached constructor";
}
emp::~emp()
{ cout< < endl< < "Reached destructor";
}
void *emp::operator new(size_t sz)
{
cout< < endl< < "Reached emp:: hello";
return pool;
}
void emp::operator delete(void *q)
{
cout< < endl< < "Reached employee::world";
}
void main()
{
clrscr();
emp *e;
e=new emp;
delete e;
}



--------------------------------------------------------------------------------

The output of the given program::

Reached emp:: hello
Reached constructor
Reached destructor
Reached employee:: world

Related Posts by Categories



0 comments:

About This Blog

Lorem Ipsum

  © Blogger templates Newspaper III by Ourblogtemplates.com 2008

Back to TOP