fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class X { public:
  5. virtual X& g (int a) {
  6. cout << 4 << endl; return *this; }
  7. virtual void f (X& ob) { ob.g(1);
  8. cout << 3 << endl; }
  9. };
  10. struct Y: X { Y() { }
  11. Y (const Y& ob) { }
  12. Y& g (int a) {
  13. cout << 9 << endl; return *this; }
  14. virtual void f (Y& ob) { ob.g(7);
  15. cout << 8 <<endl; }
  16. };
  17.  
  18. int main() {
  19. X *p = new Y();
  20. try { Y x, *r = &x;
  21. X *p = new Y();
  22. X().f(x); p-> f(x); r -> f(x);
  23. try { throw Y(); cout << 10 << endl; }
  24. catch (X&){cout << 11 << endl; }
  25.  
  26. cout << 12 << endl; }
  27. catch (Y&) {cout << 13 << endl; }
  28. cout << 14 << endl;
  29. delete p; return 0;
  30. }
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
9
3
9
3
9
8
11
12
14