What are binary operators Give an example of binary operators-00468
This subjective question is related to the book/course vu cs302 Digital Logic Design. It can also be found in vu cs302 Mid Term Solved Past Paper No. 1.
Question 1: What are binary operators. Give an example of binary operators overloading using any class.
class Complex{
private:
double real, img;
public:
…
Complex operator +(const Complex & rhs);
};
Complex Complex::operator +( const Complex & rhs){
Complex t;
t.real = real + rhs.real;
t.img = img + rhs.img;
return t;
}
Answer:
Binary Operators Overloading
Binary operators act on two quantities.
Examples of binary operators:
overloading + operator:class Complex{
private:
double real, img;
public:
…
Complex operator +(const Complex & rhs);
};
Complex Complex::operator +( const Complex & rhs){
Complex t;
t.real = real + rhs.real;
t.img = img + rhs.img;
return t;
}