Operator overloading complex number

how to do operator overloading for adding more than 2 complex numbers
like if we want to add c1+c2+c3 as we used operator overloading to add 2 complex numbers
how to do operator overloading for adding more than 2 complex numbers???

hey @taran9873 Just make sure that function adding these complex number returns an object of type complex only and number of arguments remain 2 only.

Example: C1+C2+C3, C1+C2 passed to function and result (let say r) is returned and now this r and C3 will be passed to function as arguments and result(let say r2) is returned which r2+C3.

Example: C1+C2+C3+C4, C1+C2 passed to function and result (let say r) is returned and now this r and C3 will be passed to function as arguments and result(let say r2) is returned and now this r2 and c4 is passed to function as argument and result(let say r3) which is r3+C4.

how to make + (overloaded)operator to return complex number?
can i just simple write it as
complex operator+ ()
{
}

hey @taran9873, you should arguments of type complex too.
complex operator+ (complex c1,complex c2)
{
complex res;
res.real=c1.real+c2.real;
res. img=c1.img+c2.img;
return res;
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.