LearnFrenzy
Sign in Take a free test

Operator Overloading · Operator Overloading MCQ · Question 5

Why is operator<< usually a friend function? Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links