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.
Yes, you can use getters, but sometimes if you have a lot of variables, it becomes tedious and long. And if you want to make sure that you won't by-mistake change it's value, you can declare the object as a const
Here, you don't need to have operator < as a friend, you can just make it as a member of the class and remove the 1st parameter as the operator will be called from the operand which is on the left hand side of the operator.
But operators << and >> are usually declared as friends because if you don't, you'll have to make the overload in the ostream class which isn't encouraged.
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 →
Yes, you can use getters, but sometimes if you have a lot of variables, it becomes tedious and long. And if you want to make sure that you won't by-mistake change it's value, you can declare the object as a const
Here, you don't need to have operator < as a friend, you can just make it as a member of the class and remove the 1st parameter as the operator will be called from the operand which is on the left hand side of the operator.
But operators << and >> are usually declared as friends because if you don't, you'll have to make the overload in the ostream class which isn't encouraged.