Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. /*
  2. Friend classes are able to acess the private and protected members
  3. of the class within which the friend keyword is used.
  4. */
  5. #include <iostream>
  6. using namespace std;
  7. class XYZ
  8. {
  9. private:
  10. char ch = 'A';
  11. int num = 11;
  12.  
  13. public:
  14. /* This statement would make class ABC
  15. * a friend class of XYZ, this means that
  16. * ABC can access the private and protected
  17. * members of XYZ class.
  18. */
  19. friend class ABC;
  20. };
  21. class ABC
  22. {
  23. public:
  24. void disp(XYZ obj)
  25. {
  26. cout << obj.ch << endl;
  27. cout << obj.num << endl;
  28. }
  29. };
  30. int main()
  31. {
  32. ABC obj;
  33. XYZ obj2;
  34. obj.disp(obj2);
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement