#include <iostream>
struct Base
{
Base() { std::cout << "Base" << std::endl; }
virtual ~Base() { std::cout << "~Base" << std::endl; }
int i;
};
struct Derived : public Base
{
Derived() { std::cout << "Derived" <<std::endl; }
virtual ~Derived() { std::cout << "~Derived" << std::endl; }
int it[10]; // sizeof(Base) != sizeof(Derived)
};
int main()
{
Base *bp = new Derived;
Base *bq = new Derived[5];
delete bp;
delete[] bq; // this causes runtime error
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKc3RydWN0IEJhc2UKewogIEJhc2UoKSAgICAgICAgICB7IHN0ZDo6Y291dCA8PCAiQmFzZSIgPDwgc3RkOjplbmRsOyB9CiAgdmlydHVhbCB+QmFzZSgpIHsgc3RkOjpjb3V0IDw8ICJ+QmFzZSIgPDwgc3RkOjplbmRsOyB9CiAgaW50IGk7Cn07CgpzdHJ1Y3QgRGVyaXZlZCA6IHB1YmxpYyBCYXNlCnsKICBEZXJpdmVkKCkgICAgICAgICAgeyBzdGQ6OmNvdXQgPDwgIkRlcml2ZWQiIDw8c3RkOjplbmRsOyB9CiAgdmlydHVhbCB+RGVyaXZlZCgpIHsgc3RkOjpjb3V0IDw8ICJ+RGVyaXZlZCIgPDwgc3RkOjplbmRsOyB9CiAgaW50IGl0WzEwXTsgLy8gc2l6ZW9mKEJhc2UpICE9IHNpemVvZihEZXJpdmVkKSAKfTsKCmludCBtYWluKCkKewogIEJhc2UgKmJwID0gbmV3IERlcml2ZWQ7CiAgQmFzZSAqYnEgPSBuZXcgRGVyaXZlZFs1XTsKCiAgZGVsZXRlICAgIGJwOwogIGRlbGV0ZVtdICBicTsgICAvLyB0aGlzIGNhdXNlcyBydW50aW1lIGVycm9yIAogIHJldHVybiAwOwp9