fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Foo {
  6. int x = 0;
  7. public:
  8. void inc() { x++; }
  9. int get() { return x; }
  10. };
  11.  
  12. class Bar {
  13. Foo *f;
  14. public:
  15. Bar(Foo *foo) { f = foo; }
  16. int get() const { f->inc(); return f->get(); }
  17. };
  18.  
  19. int bar(const Bar &bar) {
  20. return bar.get();
  21. }
  22.  
  23. int main() {
  24. Foo f;
  25. Bar b(&f);
  26. cout << f.get() << endl;
  27. cout << bar(b) << endl;
  28. cout << f.get() << endl;
  29. }
Success #stdin #stdout 0s 2852KB
stdin
stdout
0
1
1