fork download
  1. #include <iostream>
  2.  
  3. struct Adder
  4. {
  5. operator int () const
  6. { return result; }
  7.  
  8. Adder add (int value) const
  9. { return Adder{result + value}; }
  10.  
  11. Adder operator ()(int value) const
  12. { return add(value); }
  13.  
  14. int result = 0;
  15. };
  16.  
  17. Adder add (int value)
  18. {
  19. return Adder{value};
  20. }
  21.  
  22. int main()
  23. {
  24. std::cout << add(1)(2)(3);
  25.  
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 4304KB
stdin
Standard input is empty
stdout
6