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