fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct A
  5. {
  6. int a;
  7. };
  8.  
  9. struct B : public A
  10. {
  11. int b;
  12. };
  13.  
  14. struct C : public A
  15. {
  16. int c;
  17. };
  18.  
  19. int main() {
  20. B b;
  21. b.a = 2;
  22. b.b = 3;
  23. C c;
  24. c.a = 4;
  25. c.c = 5;
  26.  
  27. std::cout << "1. B: {" << b.a << ", " << b.b << "}\n";
  28. std::cout << "1. C: {" << c.a << ", " << c.c << "}\n";
  29.  
  30. b.A::operator =(c);
  31.  
  32. std::cout << "2. B: {" << b.a << ", " << b.b << "}\n";
  33. std::cout << "2. C: {" << c.a << ", " << c.c << "}\n";
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
1. B: {2, 3}
1. C: {4, 5}
2. B: {4, 3}
2. C: {4, 5}