Question 18
Back to Exercise
Why is operator<< for printing your class written as a non-member (often a friend)?
- A Members cannot return references
- B In std::cout << obj the left operand is the stream; a member operator would need your object on the left (obj << std::cout) Correct
- C It must be static
- D Streams cannot be passed to members
Correct Answer: Option B
Making it a friend lets it read private members without public getters.
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!