Operator overloading is —
2022
Operator overloading is —
- A.
making new C++ operators
- B.
making C++ operators work with objects
- C.
giving C++ operators more than they can handle
- D.
helping in reducing execution time
Attempted by 233 students.
Show answer & explanation
Correct answer: B
Operator overloading: Operator overloading allows existing C++ operators (for example +, -, *) to be given definitions that work with user-defined types (classes or structs). Key idea: You implement operator functions (such as operator+) to specify how an operator behaves for your class. These functions can be member functions or non-member functions.
Example: To add two Complex objects, define a function such as Complex operator+(const Complex& a, const Complex& b) that returns their sum.
A video solution is available for this question — log in and enroll to watch it.