fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class complex {
  5. double re, im;
  6. public:
  7. complex(double r, double i) : re{ r }, im{ i } {}
  8. complex& operator+=(const complex& other) { re += other.re; im += other.im; return *this; }
  9. };
  10.  
  11. inline complex operator+(complex lhs, const complex& rhs)
  12. {
  13. lhs += rhs;
  14. return lhs;
  15. }
  16.  
  17. int main()
  18. {
  19. complex a{ 1, 1 };
  20. complex b{ 2, -3 };
  21. a += {1, 3};
  22. a = b + (complex){1, 2};
  23. }
  24.  
Success #stdin #stdout 0s 3136KB
stdin
Standard input is empty
stdout
Standard output is empty