fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class MyClass {
  5. int x;
  6. public:
  7. MyClass(int a) { x = a; };
  8. void method(MyClass &m);
  9. };
  10.  
  11. void MyClass::method(MyClass &m){
  12. cout << "self.x = " << x << "; m.x = " << m.x << endl;
  13. }
  14.  
  15. int main() {
  16. MyClass o1(5);
  17. MyClass o2(10);
  18.  
  19. o1.method(o2);
  20. o2.method(o1);
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
self.x = 5; m.x = 10
self.x = 10; m.x = 5