Advertisements
Advertisements
प्रश्न
State characteristics of Friend Function.
दीर्घउत्तर
Advertisements
उत्तर
- 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
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
