Advertisements
Advertisements
Question
State characteristics of Friend Function.
Long Answer
Advertisements
Solution
- Even though it’s declared inside a class, it isn’t a “member.” You don’t use
object.function()To call it, you just call it like a regular function. - This is a common point of confusion. While it has permission to see private data, it doesn't "live" inside the object, so it must be told which object to look at using the dot operator (e.g.,
obj.data). - It doesn't matter if you put the
frienddeclaration underpublic:orprivate:Its status and access rights remain exactly the same. - Since it’s not a member function (and doesn’t have a
thispointer), it almost always takes an object of the class as a parameter, so it has something to work on.
shaalaa.com
Is there an error in this question or solution?
