SabirSazzad

Friend Function test

Feb 23rd, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class B;
  4. class A
  5. {
  6. private:
  7.     int hight;
  8. public:
  9.     A();
  10.     friend int sum(A,B);
  11. };
  12. class B
  13. {
  14. private:
  15.     int hight2;
  16. public:
  17.     B();
  18.     friend int sum(A,B);
  19. };
  20. A::A()
  21. {
  22.     hight = 10;
  23. }
  24. B::B()
  25. {
  26.     hight2 = 20;
  27. }
  28. int sum (A a, B b)
  29. {
  30.     return (a.hight+b.hight2);
  31. }
  32.  
  33. int main ()
  34. {
  35.     A a;
  36.     B b;
  37.  
  38.     cout << sum(a,b);
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment