We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Since an ostream does not have access to private variables of Box, it makes sense to enable access via friend
However for a greater / less than comparison, since we are just dealing with two Box's and already have access to their private variables, we don't need to friend that method
I may be COMPLETELY wrong here but mine works without using a friend method for less than or equal comparison overloads
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Box It!
You are viewing a single comment's thread. Return to all comments →
It depends on what you are overloading
Since an ostream does not have access to private variables of Box, it makes sense to enable access via friend
However for a greater / less than comparison, since we are just dealing with two Box's and already have access to their private variables, we don't need to friend that method
I may be COMPLETELY wrong here but mine works without using a friend method for less than or equal comparison overloads