fork download
  1.  
  2. #include <iostream>
  3. using namespace std ;
  4.  
  5.  
  6. class Other
  7. {
  8. public:
  9. void fun(){
  10.  
  11. cout << 2 << endl;
  12. };
  13. };
  14.  
  15. class WithFriend
  16. {
  17. private:
  18. int i;
  19. public:
  20. void getdata(); // Member function of class WithFriend
  21.  
  22. // making function of class Other as friend here
  23. friend void Other::fun();
  24.  
  25. // making the complete class as friend
  26. friend class Other;
  27. };
  28.  
  29.  
  30.  
  31. int main()
  32. {
  33.  
  34.  
  35. WithFriend wf ;
  36.  
  37. Other ox ;
  38.  
  39. ox.fun() ;
  40.  
  41. }
  42.  
Success #stdin #stdout 0s 5560KB
stdin
Standard input is empty
stdout
2