fork download
  1. #include <iostream>
  2. #include <stdexcept>
  3. using namespace std;
  4.  
  5. class A
  6. {
  7. public:
  8. A* operator -> ()
  9. {
  10. if ( m_value < 0 )
  11. throw std::out_of_range("must be positive");
  12.  
  13. return this;
  14. }
  15. int Get()
  16. {
  17. return m_value;
  18. }
  19. private:
  20. int m_value = 1;
  21. };
  22.  
  23.  
  24. int main() {
  25.  
  26. A a;
  27.  
  28. int n1 = a->Get();
  29. int n2 = a.Get();
  30.  
  31. cout << n1 << ", " << n2 << endl;
  32.  
  33. // your code goes here
  34. return 0;
  35. }
Success #stdin #stdout 0s 15224KB
stdin
Standard input is empty
stdout
1, 1