|
|
|
|
|
by dgrunwald
26 days ago
|
|
But it's possible for `delete tmp;` to call a user-defined `operator delete()` in the derived class! https://godbolt.org/z/hvePa6jMP The way this works under the hood is that every polymorphic class has two destructors (so two destructor entries in the vtable): the "complete object destructor" is the ~A() you know from C++, and then there's also the "deleting destructor" which combines ~A() + delete. So the deleting destructor can call free() while knowing the derived object size, even for a delete-via-base-class-pointer. |
|