struct A { int i; A(int i_) : i(i_) {} virtual const char* fn() { return "A"; } };
struct B : public A {
int j;
B(int i_) : A(i_), j(i_ + 10) {}
virtual const char* fn() { return "B"; }
};
#include <iostream>
#include <cstring>
int main()
{
A* a = new A(1);
B* b = new B(2);
*a = *b; // aka a->operator=(static_cast<A*>(*b));
std::cout << "sizeof A = " << sizeof(A)
<< ", a->i = " << a->i << ", a->fn(): " << a->fn() << '\n';
}
ICAgIHN0cnVjdCBBIHsgaW50IGk7IEEoaW50IGlfKSA6IGkoaV8pIHt9IHZpcnR1YWwgY29uc3QgY2hhciogZm4oKSB7IHJldHVybiAiQSI7IH0gfTsKICAgIHN0cnVjdCBCIDogcHVibGljIEEgewogICAgCWludCBqOwogICAgCUIoaW50IGlfKSA6IEEoaV8pLCBqKGlfICsgMTApIHt9CiAgICAgICAgdmlydHVhbCBjb25zdCBjaGFyKiBmbigpIHsgcmV0dXJuICJCIjsgfQogICAgfTsKCiAgICAjaW5jbHVkZSA8aW9zdHJlYW0+CiAgICAjaW5jbHVkZSA8Y3N0cmluZz4KICAgIAogICAgaW50IG1haW4oKQogICAgewogICAgICAgIEEqIGEgPSBuZXcgQSgxKTsKICAgICAgICBCKiBiID0gbmV3IEIoMik7CiAgICAgICAgKmEgPSAqYjsgLy8gYWthIGEtPm9wZXJhdG9yPShzdGF0aWNfY2FzdDxBKj4oKmIpKTsKICAgICAgICBzdGQ6OmNvdXQgPDwgInNpemVvZiBBID0gIiA8PCBzaXplb2YoQSkKICAgICAgICAgICAgPDwgIiwgYS0+aSA9ICIgPDwgYS0+aSA8PCAiLCBhLT5mbigpOiAiIDw8IGEtPmZuKCkgPDwgJ1xuJzsKICAgIH0gICAgICAgCg==