fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A
  5. {
  6. };
  7.  
  8. class C;
  9.  
  10. class B : public A
  11. {
  12. public:
  13. B& operator=(const C& rhs);
  14.  
  15. int x;
  16. };
  17.  
  18. class C : public A
  19. {
  20. public:
  21. C& operator=(const B& rhs);
  22.  
  23. int x;
  24. };
  25.  
  26. B& B::operator=(const C& c)
  27. {
  28. x = c.x;
  29. }
  30.  
  31. C& C::operator=(const B& b)
  32. {
  33. x = b.x;
  34. }
  35.  
  36. int main()
  37. {
  38. B b;
  39. b.x = 5;
  40.  
  41. C c;
  42. c = b;
  43.  
  44.  
  45. cout << c.x << "\n";
  46. return 0;
  47. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
5