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

View previous topic View next topic Go down

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 on 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;
}
avatar
iamdsc_0410

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

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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