Question 2
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
int operator+(int a, int b) { return a - b; }
int main() {
std::cout << 5 + 3 << '\n';
return 0;
}
- A The function needs to be inline
- B An overloaded operator needs at least one operand of class or enumeration type; built-in int + int cannot be redefined Correct
- C It must return long
- D operator+ must be a member
Correct Answer: Option B
The language protects the meaning of operations on built-in types.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!