Disallowing object creation on heap
Object of a class can be created dynamically on heap or statically on Stack or Data Area. If we have a class MyClass, then the below objects will be created on heap. // Operator: New MyClass *ptr1 = new MyClass(); // Crating object of MyClass on heap. // Operator: New-Array MyClass *ptr2 = new MyClass[10]; // […]
Out of memory condition in C++ for new operator
How will you handle a situation if new operator is not able to allocate memory on heap to your program? In C language malloc returns NULL, if it is not able to allocate memory, so the check can be as below: int *ptr = malloc(sizeof(int)); if (ptr == NULL) ; // malloc not able to […]