Overload Operators

  • + 0 comments
    Complex operator+(const Complex& c1, const Complex& c2) {
        Complex result;
        result.a = c1.a + c2.a; // Sum of real parts
        result.b = c1.b + c2.b; // Sum of imaginary parts
        return result;
    }
    
    std::ostream& operator<<(std::ostream& os, const Complex& c) {
        os << c.a << "+i" << c.b;
        return os;
    }