Machine-translated by Google. Questions are authored in English.
Top

Discussion

A friend function can be used to

  • A.avoid arguments between classes.
  • B.allow access to classes whose source code is unavailable.
  • C.allow one class to access an unrelated class.
  • D.None of the above

Answer: C

A friend function can be used to allow one class to access another, unrelated class. A function declared as a friend of a class can reach its private and protected members, and a friend function of two classes can read the members of both, which gives them a way to share data without being related by inheritance. A friend does not avoid arguments between classes, and it cannot give access to classes whose source code is not available because the friend declaration has to be written inside the class. A common example is an operator function that needs to read the private data of two different classes at once.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.