fork(1) 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. *a = *b; // aka a->operator=(static_cast<A*>(*b));
  12. std::cout << "sizeof A = " << sizeof(A)
  13. << " a->fn(): " << a->fn() << '\n';
  14. }
  15.  
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
sizeof A = 4 a->fn(): A