A
Q. An operator function is created using _____________ keyword.
- Correct Answer - Option(B)
- Views: 22
- Filed under category C++
- Hashtags:
A
In C++, operator overloading allows you to define how operators (like +, -, *, ==, etc.) behave for objects of your class. To create an operator function, you use the operator keyword.
Example:
class Complex {
public:
int real, imag;
Complex(int r, int i) : real(r), imag(i) {}
// Overload the + operator
Complex operator+(const Complex& other) {
return Complex(real + other.real, imag + other.imag);
}
};
Here, operator+ is the operator function.
✅ Correct Answer: (B) operator
You must be Logged in to update hint/solution
Be the first to start discuss.
Discusssion
Login to discuss.