Friend function Can access private, protected and public members of a class 

By: Prof. Dr. Fazal Rehman | Last updated: February 3, 2024

Let’s begin with a programming example in which I will show you how a friend function Can access private, protected, and public members of a class.

Example of Friend function Can access private and protected data members in C++
Example of Friend function Can access private and protected data members in C++

C++ Example: Friend function Can access private data members of a class

  Output Sum: 2

C++ Example: Friend function Can access protected data members of a class

Output Sum: 2

 C++ Example: Friend function Can access public data members of a class

Output Sum: 2  
All Copyrights Reserved 2025 Reserved by T4Tutorials