fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Base {
  5. int x;
  6. Base(int x) : x(x) {}
  7. };
  8. struct Derived1 : public Base {
  9. Derived1(int x) : Base(x) {}
  10. };
  11. struct Derived2 : public Base {
  12. Derived2(int x) : Base(x) {}
  13. };
  14.  
  15. int main() {
  16. Derived1 d1(5);
  17. Derived2 d2(10);
  18. cout << d1.x << " " << d2.x << endl;
  19. ((Base&)d1) = (Base&)d2;
  20. cout << d1.x << " " << d2.x << endl;
  21. return 0;
  22. }
Success #stdin #stdout 0s 4440KB
stdin
Standard input is empty
stdout
5 10
10 10