fork download
  1. #include <iostream>
  2. #include <memory>
  3. #include <functional>
  4.  
  5. struct S
  6. {
  7. void operator =(int y)
  8. { x = 5; }
  9.  
  10. operator int*()
  11. {
  12. return &x;
  13. }
  14.  
  15. int x;
  16. };
  17.  
  18. std::ostream& operator <<(std::ostream& out, S const& s)
  19. {
  20. return out << s.x;
  21. }
  22.  
  23. int main()
  24. {
  25. S s;
  26. auto x = std::make_shared<S>(std::ref(s));
  27. *x = 10;
  28.  
  29. std::cout << *x;
  30. }
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
5