C++ program : to access private member of two class using Friend function




#include<iostream.h>
#include<conio.h>
class second;
class first
{
   int s1;
   public:
   void enter()
   {
      cout<<"Enter the S1 : ";
      cin>>s1;
   }
   friend int fun(first,second);
};
class second
{
   int s2;
   public:
   void get()
   {
      cout<<"Enter the S2:";
      cin>>s2;
   }
   friend int fun(first, second);
};
int fun(first f1,second f2)
{
   return f1.s1+f2.s2;
}
int main()
{
   clrscr();
   first ob1;
   second ob2;
   ob1.enter();
   ob2.get();
   cout<<"The Sum of two object is : "<<fun(ob1,ob2);
   getch();
   return 0;
}








//       Special Thanks to Gostkiller( Midhul N )...


Class diagram 

(click image to view large)

 

 



Related Posts:

0 comments:

Post a Comment