C++ Programming Blog

 
 
 

Image

 #include<iostream.h>
 #include<conio.h>


 //-------------------------  CLass Declarations  ------------------------//


 class two;


 //------------------------------  one  ----------------------------------//


 class one
    {
       private:
        int data_1;

       public:
        one() { data_1=100; }
        friend int access_both(one,two);
    };


 //------------------------------  two  ----------------------------------//


 class two
    {
       private:
        int data_2;

       public:
        two() { data_2=100; }
        friend int access_both(one,two);
    };


 //-------------------------  access_boyh(one,two)  ----------------------//


 int access_both(one a,two b)
    {
       return (a.data_1+b.data_2);
    }


 main()
    {
       clrscr();

       one a;
       two b;

       cout<<\"\\n Data returned by the function access_both(one,two) = \";
       cout<<access_both(a,b);

       getch();
       return 0;
    }

 
 
Didn't find what you were looking for? Find more on Program to illusrate the use of friend functions