tampurus

6 friend function

Dec 2nd, 2021 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class second;
  4. class first{
  5.     int x;
  6.     public:
  7.     void getvalue(){
  8.         cout<<"Enter number ";
  9.         cin>>x;
  10.     }
  11.     friend void sum(first,second);
  12. };
  13. class second{
  14.     int y;
  15.     public:
  16.     void getvalue(){
  17.         cout<<"Enter number ";
  18.         cin>>y;
  19.     }
  20.     friend void sum(first,second);
  21. };
  22. void sum(first a , second b){
  23.     cout<<"\nsum is "<<a.x+b.y;
  24. }
  25. int main()
  26. {
  27.     first a;
  28.     second b;
  29.     a.getvalue();
  30.     b.getvalue();
  31.     sum(a,b);
  32.     return 0;
  33. }
  34. /*
  35. Output
  36. Enter number 1
  37. Enter number 2
  38.  
  39. sum is 3
  40. */
Advertisement
Add Comment
Please, Sign In to add comment