Next we introduce a function
cadd for adding two complex numbers.
caddis defined outside the class definition. So it is not a class method. It just operates on complex objects just as the math library function
sqrtoperates on double precision numbers. Here, the function
caddtakes two complex variables as arguments. They are declared as references. Passing pointers or references is customary for arguments that are not simple base types. For large classes this practice is more efficient. The function return type is complex. The
returnstatement that generates the return value uses the
complexconstructor with two arguments. Those arguments are themselves expressions. The expressions specify how the two complex numbers are added, namely by adding separately their real and imaginary parts.
The function is invoked in the main program in the usual way and the result
is stored in the variable