Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It is certainly Standard Behavior. If the derived class's operator new was used, <em>its</em> operator delete will also be used (also note even though you do not explicitly tell the compiler those functions are static, they <em>are</em> implicitly declared so). There might be the naughty case where you have an operator new in the derived class, but the corresponding operator delete is in the base class. I think that's valid, but i would avoid that. Relying on the base operator delete, while defining ones own operator new in the derived class will inevitable cause trouble. </p> <blockquote> <p>If I don't define ANY destructors then I get what I expected to happen:</p> </blockquote> <p>You will get undefined behavior :) Everything can happen, including something you would expect (wrongly). Deleting through a base pointer that points to an object of another type requires a virtual destructor. The implicitly declared destructor is not virtual. </p> <blockquote> <p>When should I be using void operator delete( void *, size_t );</p> </blockquote> <p>If you want to have the size that was allocated known in the operator delete. I wrote about what it means here: <a href="https://stackoverflow.com/questions/377178/how-does-the-standard-new-operator-work-in-c#390585">What does the C++ new operator do other than allocation and a ctor call?</a> . If you use (from within your overloaded member operator delete/new) the global operator new &amp; delete to get your memory and release it, or even malloc / free, you don't need that size information. But it could be useful for logging purposes. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload