Search Avyanna
General Programming Programming Languages

FRIEND FUNCTION IN C++   

#C++


pic20

Joe Waiganjo
@Techy.Rack · Updated 08 Apr. 2021

FRIEND FUNCTION IN C++ Friend Function in C++ Data hiding is a fundamental concept of object-oriented programming. It restricts the access of private members from outside of the class. Similarly, protected members can only be accessed by derived classes and are inaccessible from outside. However, there is a feature in C++ called friend functions that break this rule and allow us to access member functions from outside the class. A friend function can access the private and protected data of a class. We declare a friend function using the friend keyword inside the body of the class. Characteristics of a Friend function: The function is not in the scope of the class to which it has been declared as a friend. It cannot be called using the object as it is not in the scope of that class. It can be invoked like a normal function without using the object. It cannot access the member names directly and has to use an object name and dot membership operator with the member name. It can be declared either in the private or the public part. It has an object of the class as a parameter. It is declared within the class scope and preceded with the keyword friend. more on FRIEND FUNCTION IN C++


Please login to add your answer