在More Effective中:
Consider the following code:
class B { public: virtual ~B(); void operator delete ( void*, size_t ) throw(); void operator delete[]( void*, size_t ) throw(); void f( void*, size_t ) throw(); }; class D : public B { public: void operator delete ( void* ) throw(); void operator delete[]( void* ) throw(); };
Why do B's operators delete have a second parameter, whereas D's do not?
The answer is: It's just preference, that's all. Both are usual deallocation functions, not placement deletes. (For those keeping score at home, see section 3.7.3.2/2 in the C++ standard.)
不知道preference是什么? 为什么不是placement delete?
Continuing with the same piece of code: Which operator delete() is called for each of the following delete expressions? Why, and with what parameters?
D* pd1 = new D;
delete pd1;
This calls D::operator delete(void*).
B* pb1 = new D; delete pb1;
This also calls D::operator delete(void*). Since B's destructor is virtual, of course D's destructor is properly called, but the fact that B's destructor is virtual also implicitly means that D::operator delete() must be called, even though B::operator delete() is not (in fact, cannot be) virtual.
As an aside to those who are interested in how compilers implement these things: The usual method is that the code actually generated for every destructor is given an invisible "when done destroying the object, should I delete it?" flag that is set appropriately (false when destroying an automatic object, true when destroying a dynamic object). The last thing the generated destructor code does is check the flag and, if it's true, call the correct operator delete().[1] This technique automatically ensures the correct behavior, namely that operator delete() appears to act "virtually" even though it is a static function and, therefore, cannot be virtual.
从这里了解到delete时,先找到对应的destructor, 这里自然就是D:~D(),然后在调用operator delete,自然也是D::operator delete(void*). 不管pbl是B*