I was messing around operator overloading and I've noticed that on inherited object, the overloaded operator delete doesn't seem to execute when the inherited object has an operator new overloaded:
#include <iostream>
#include <string>
class TestAbs {
public:
TestAbs (void) {
}
virtual ~TestAbs (void) noexcept {
}
};
class Test : public TestAbs {
public:
Test (void)
: TestAbs () {
}
~Test (void) noexcept override {
}
void* operator new (size_t) throw () {
std::cout << "Overloaded operator new!\n";
return nullptr;
}
void operator delete (void*) noexcept {
std::cout << "Overloaded operator delete in class: Test!\n";
}
};
int main() {
TestAbs* tp = new Test ();
delete tp;
return 0;
}
The code above has the following output:
Overloaded operator new!
What happened to the overloaded operator delete? Thank you all in advance!
Update: Thank you guys for all the help. It seems like the problem was indeed the nullptr return on the overloaded new.