Question 5
Back to Exercise
Why is operator<< for printing a class written as a non-member (often a friend)?
- A Members cannot return references
- B The left operand is std::ostream, not your class; friend gives it access to private members Correct
- C It is faster
- D The standard forbids member operators
Correct Answer: Option B
As a member, the call would have to be written obj << std::cout.
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!