fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class Complex {
  5. private:
  6. int real, imag;
  7. public:
  8. Complex(int r = 0, int i = 0) { real = r; imag = i; }
  9. Complex operator + (Complex const &obj) {
  10. Complex res;
  11. res.real = real + obj.real;
  12. res.imag = imag + obj.imag;
  13. return res;
  14. }
  15. void print() { cout << real << " + i" << imag << endl; }
  16. };
  17.  
  18. int main() {
  19. Complex c1(10, 5), c2(2, 4);
  20. Complex c3 = c1 + c2;
  21. c3.print();
  22. }
  23.  
  24. //https://pt.stackoverflow.com/q/395741/101
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
12 + i9