fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A
  5. {
  6. int x;
  7. public:
  8. A& operator=(const A& param)
  9. {
  10. cout << "operator=\n";
  11. x = param.x;
  12. return *this;
  13. }
  14. operator int&()
  15. {
  16. cout << "operator()\n";
  17. return x;
  18. }
  19. A(const int& param)
  20. {
  21. x = param;
  22. }
  23. void putX()
  24. {
  25. cout << "x = " << x << endl;
  26. }
  27. };
  28. int main()
  29. {
  30. A a(999);
  31. a = a + 33;
  32. a.putX();
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
operator()
operator=
x = 1032