fork(4) download
  1. struct A { virtual const char* fn() { return "A"; } };
  2. struct B : public A { virtual const char* fn() { return "B"; } };
  3.  
  4. #include <iostream>
  5. #include <cstring>
  6.  
  7. int main()
  8. {
  9. A* a = new A();
  10. B* b = new B();
  11. memcpy(a, b, sizeof(A));
  12. std::cout << "sizeof A = " << sizeof(A)
  13. << " a->fn(): " << a->fn() << '\n';
  14. }
  15.  
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
sizeof A = 4 a->fn(): B