#include <iostream>
struct pad {
int x;
virtual ~pad() {}
};
struct b {
int x;
};
struct vb {
int x;
virtual ~vb() {}
};
struct d : pad, b, vb {};
void operator delete( void *p ) {
std::cout << "free " << p << '\n';
}
int main() {
std::cout << "With virtual destructor:\n";
d *p = new d;
std::cout << "allocate " << p << ", delete " << static_cast< vb * >( p ) << '\n';
delete static_cast< vb * >( p );
std::cout << "With plain destructor:\n";
p = new d;
std::cout << "allocate " << p << ", delete " << static_cast< b * >( p ) << '\n';
delete static_cast< b * >( p );
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKc3RydWN0IHBhZCB7CiAgICBpbnQgeDsKICAgIAogICAgdmlydHVhbCB+cGFkKCkge30KfTsKCnN0cnVjdCBiIHsKICAgIGludCB4Owp9OwoKc3RydWN0IHZiIHsKICAgIGludCB4OwogICAgCiAgICB2aXJ0dWFsIH52YigpIHt9Cn07CgpzdHJ1Y3QgZCA6IHBhZCwgYiwgdmIge307Cgp2b2lkIG9wZXJhdG9yIGRlbGV0ZSggdm9pZCAqcCApIHsKICAgIHN0ZDo6Y291dCA8PCAiZnJlZSAiIDw8IHAgPDwgJ1xuJzsKfQoKaW50IG1haW4oKSB7CiAgICBzdGQ6OmNvdXQgPDwgIldpdGggdmlydHVhbCBkZXN0cnVjdG9yOlxuIjsKICAgIGQgKnAgPSBuZXcgZDsKICAgIHN0ZDo6Y291dCA8PCAiYWxsb2NhdGUgIiA8PCBwIDw8ICIsIGRlbGV0ZSAiIDw8IHN0YXRpY19jYXN0PCB2YiAqID4oIHAgKSA8PCAnXG4nOwogICAgZGVsZXRlIHN0YXRpY19jYXN0PCB2YiAqID4oIHAgKTsKCiAgICBzdGQ6OmNvdXQgPDwgIldpdGggcGxhaW4gZGVzdHJ1Y3RvcjpcbiI7CiAgICBwID0gbmV3IGQ7CiAgICBzdGQ6OmNvdXQgPDwgImFsbG9jYXRlICIgPDwgcCA8PCAiLCBkZWxldGUgIiA8PCBzdGF0aWNfY2FzdDwgYiAqID4oIHAgKSA8PCAnXG4nOwogICAgZGVsZXRlIHN0YXRpY19jYXN0PCBiICogPiggcCApOwp9Cg==