C++ Programming Code Examples C++ > Beginners Lab Assignments Code Examples Similar to friend class, this function can access the private and protected members of another class. Similar to friend class, this function can access the private and protected members of another class. A global function can also be declared as friend as shown in the example below: #include <iostream> using namespace std; class XYZ { private: int num=88; char ch='Z'; public: friend void disp(XYZ obj); }; //Global Function void disp(XYZ obj){ cout<<obj.num<<endl; cout<<obj.ch<<endl; } int main() { XYZ obj; disp(obj); return 0; }