OVERLOADING NEW AND DELETE OPERATOR - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Tuesday, October 26, 2010

OVERLOADING NEW AND DELETE OPERATOR


PROGRAM:

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class op
{
public:
            void *operator new(size_t size, char const *file,int line);
            void operator delete(void *p);
};
void *op::operator new(size_t size, char const *file,int line)
{
 void *p = malloc(size);
 cout<<"\n New called the file:"<<file<<"\n line:"<<line<<"\n size:"<<size<<"\n p:"<<p<<endl;
 return p;
 }
void op::operator delete(void *p)
{
 cout<<"\n Delete called p:"<<p<<endl;
 free(p);
 }
void main()
{
clrscr();
op *X = new(__FILE__,__LINE__)op;
delete X;
getch();
}

No comments:

Post a Comment