Who is online? In total there is 1 user online :: 0 Registered, 0 Hidden and 1 Guest None [ View the whole list ] Most users ever online was 7 on Tue Jun 02, 2020 6:34 am feeds | Overloading new and delete operator program Mon May 08, 2017 8:27 pm by Prateek Gupta - Code:
#include <iostream>
#include <stdlib.h>
using namespace std;
class Number
{
private:
int *arr;
public:
void *operator new(size_t size)
{
void *ptr = ::new int[size];
return ptr;
}
void operator delete(void *ptr)
{
::delete(ptr);
cout<<"Memory deallocated"<<endl;
}
void get_data();
void show_data();
};
void Number::get_data()
{
arr= (int *)malloc(10*sizeof(int));
cout<<"Enter the elements"<<endl;
for(int i=0;i<5;i++)
cin>>arr[i];
}
void Number::show_data()
{
for(int i=0;i<5;i++)
cout<<arr[i]<<" ";
cout<<endl;
}
int main()
{
Number *n = new Number;
n->get_data();
n->show_data();
delete n;
return 0;
}
Comments: 1 | April 2024 Mon | Tue | Wed | Thu | Fri | Sat | Sun |
---|
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | | | | | |
Calendar Most active topic starters Statistics We have 10 registered users The newest registered user is shivendraOur users have posted a total of 44 messages in 19 subjects |
Sun May 14, 2017 11:57 am by akarshsomani
» IP6: Write a C++ program that uses the concept of hybrid inheritance.
Sun May 14, 2017 10:55 am by iamdsc_0410
» Overloading new and delete operator program
Sat May 13, 2017 7:29 am by akarshsomani
» Constructos and Destructors assignment question:CD-3
Thu May 11, 2017 1:57 pm by Prateek Gupta
» Program related to Object Slicing : Why the output is not coming In Base a=2 ?
Fri May 05, 2017 7:36 am by akarshsomani
» Program given by sir i.e given in Reema Thareja on Overloading of new and delete operators is not working . Debug it !!
Mon May 01, 2017 9:11 am by iamdsc_0410
» constructor and destructor assignment solutions
Mon Apr 24, 2017 8:10 am by akarshsomani
» class and objects assignment solutions.
Fri Apr 21, 2017 9:01 pm by iamdsc_0410
» SMARKET SOLUTION
Tue Apr 18, 2017 6:33 pm by iamdsc_0410