Why is this an issue?
Overriding operator new
typically indicates that custom memory allocation is required for the class. When that’s the case, it must be
balanced with a custom memory deallocation in a matching operator delete
method. Otherwise memory leaks or memory corruption will
result.
Noncompliant code example
class AirPlane
{
public:
void* operator new(size_t size);
void fly();
};
Compliant solution
class AirPlane
{
public:
void* operator new(size_t size);
void operator delete(void* deadObject, size_t size);
void fly();
};
Resources