Coding Discussions
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Program given by sir i.e given in Reema Thareja on Overloading of new and delete operators is not working . Debug it !!

Go down

Program given by sir i.e given in Reema Thareja on Overloading of new and delete operators is not working . Debug it !!  Empty Program given by sir i.e given in Reema Thareja on Overloading of new and delete operators is not working . Debug it !!

Post by iamdsc_0410 Mon May 01, 2017 9:11 am

Code:
#include<iostream>
using namespace std;
class Array
{
private:
int *arr;
public:
void * operator new(size_t size)
{
void *parr=::new int[size];
return parr;
}
void operator delete(void *parr)
{
::delete parr;
}
void get_data();
void show_data();
};
void Array::get_data()
{
cout<<"\nEnter the elements: ";
for(int i=0;i<5;i++)
cin>>arr[i];
}
void Array::show_data()
{
cout<<"\nThe Array is : ";
for(int i=0;i<5;i++)
cout<<" "<<arr[i];
}
int main()
{
Array *A = new Array;
A->get_data();
A->show_data();
delete A;
return 0;
}
iamdsc_0410
iamdsc_0410

Posts : 14
Join date : 2017-04-11
Age : 26
Location : IIIT Kalyani

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum