[go: up one dir, main page]

0% found this document useful (0 votes)
10 views1 page

Oop 10

The document presents a C++ program that demonstrates the overloading of memory management operators. It defines a class 'Box' with custom new and delete operators to manage memory allocation and deallocation, displaying messages when these operations occur. The main function creates and deletes an instance of 'Box', triggering the overloaded operators.

Uploaded by

meenaverma1470
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Oop 10

The document presents a C++ program that demonstrates the overloading of memory management operators. It defines a class 'Box' with custom new and delete operators to manage memory allocation and deallocation, displaying messages when these operations occur. The main function creates and deletes an instance of 'Box', triggering the overloaded operators.

Uploaded by

meenaverma1470
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Practical-10

Write a program to demonstrate the overloading of memory


management operators.

Program:
#include <iostream>
#include <cstdlib>
using namespace std;
class Box {
private:
int size;
public:
Box() {
cout << "CONSTRUCTOR CALLED" << endl;
}
~Box() {
cout << "DESTRUCTOR CALLED" << endl;
}
void* operator new(size_t size) {
cout << "MEMORY ALLOCATED" << endl;
void* p = malloc(size);
return p;
}
void operator delete(void* p) {
cout << "MEMORY DEALLOCATED" << endl;
free(p);
}
};
int main() {
Box* b = new Box();
delete b;
return 0;
}

Output:

You might also like