Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. /*
  2. Friend functions are functions that if declared within a class
  3. are able to access private and protected members of that class.
  4. */
  5. #include <iostream>
  6. using namespace std;
  7. class XYZ
  8. {
  9. private:
  10. int num = 100;
  11. char ch = 'Z';
  12.  
  13. public:
  14. friend void disp(XYZ obj);
  15. };
  16. //Global Function
  17. void disp(XYZ obj)
  18. {
  19. cout << obj.num << endl;
  20. cout << obj.ch << endl;
  21. }
  22. int main()
  23. {
  24. XYZ obj;
  25. disp(obj);
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement