Thursday, 3 January 2013

What is operator overloading? | OOPS

Operator overloading is a function where different operators are applied and depends on the arguments. Operator,-,* can be used to pass through the function , and it has their own precedence to execute.
Example:
class complex
{
double real, imag;
public:
complex(double r, double i) :
real(r), imag(i)
{
}
complex operator+(complex a, complex b);
complex operator*(complex a, complex b);
complex& operator=(complex a, complex b);
}
a=1.2, b=6

No comments: