What is the use of friend function?

Answer Posted / damodar narayan

Visibility

The visibility of a property or method can be defined by prefixing the declaration with the keywords public, protected or private. Class members declared public can be accessed everywhere. Members declared protected can be accessed only within the class itself and by inherited and parent classes. Members declared as private may only be accessed by the class that defines the member.

The policy is if you are not a member, you can’t get it. But there is a certain situation wherein you need to share your private or protected data with nonmembers. ‘Friends’ come here as a rescue.

A friend function is a non-member function that grants access to class’s private and protected members.

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is php front end or back end?

513


What is mvc php?

524


What is php built on?

511


What are the different components used in php for formatting?

538


What is mysqli_real_escape_string?

529






What is the purpose of basename() function in PHP?

602


Is overloading possible in php?

524


What is session_register()?

560


What is a variable cost example?

555


How to get the ip address of the client?

8702


Why php language is used?

528


How can php and javascript interact?

751


Swap two variables value without using third variable in php ?

598


what are interfaces and Abstart classes

1470


Which function will suitably replace 'x' if the size of a file needs to be checked? $Size=x(filename);

557