Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Friend functions are functions that if declared within a class
- are able to access private and protected members of that class.
- */
- #include <iostream>
- using namespace std;
- class XYZ
- {
- private:
- int num = 100;
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement