LibertyPaul

8lab.friendly classes

May 15th, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class A;
  4.  
  5. class B{
  6.     int inf;
  7.     public:
  8.     void set_inf(int a){
  9.         inf=a;
  10.     }
  11.     int get_inf(){
  12.         return inf;
  13.     }
  14.     friend class A;
  15. };
  16.  
  17. class A{
  18.     char c;
  19.     public:
  20.     int infout(B obj){
  21.         return obj.get_inf();
  22.     }
  23. };
  24.  
  25. int main(){
  26.     A one;
  27.     B two;
  28.     two.set_inf(42);
  29.     cout<<one.A::infout(two)<<endl;
  30.    
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment