Difficulty: Easy
Correct Answer: The program will print the output 20.
Explanation:
Introduction / Context:
This question validates understanding of member operator overloading and default arguments. A member operator+(int) computes a new Addition whose x is the receiver’s x plus the provided integer. Default arguments on operators are allowed in C++ and are not the cause of any compilation issue here.
Given Data / Assumptions:
Concept / Approach:
Member operator+(int) is analogous to a method call objA.operator+(5). It builds a temporary result object with the sum and returns it by value. No undefined behavior occurs; the temporary is copied into objB.
Step-by-Step Solution:
Verification / Alternative check:
If you omit the argument (objA + ), the default argument 0 would be used and the result would be 15. The code as written provides 5 explicitly.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing member versus non-member operator overload constraints, or assuming default arguments are disallowed for overloaded operators.
Final Answer:
The program will print the output 20.
Discussion & Comments