fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Complex {
  5. double re, im;
  6. Complex(double r, double i): re(r), im(i) {}
  7. friend Complex operator+(const Complex l, const Complex r) {
  8. return Complex(r.re + l.re, r.im + l.im); // zwracamy nowo utworzony obiekt...
  9. }
  10.  
  11. friend ostream& operator<<(ostream& out, const Complex c) {
  12. return out << "(" << c.re << ", " << c.im << ")";
  13. }
  14. };
  15.  
  16. int main(void) {
  17. cout << (Complex(20, 2) + Complex(20, 2));
  18. }
Success #stdin #stdout 0s 3344KB
stdin
Standard input is empty
stdout
(40, 4)