C++ Programming Blog

 
 
 

Image

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


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


 class beta;


 //------------------------------  alpha  --------------------------------//


 class alpha
    {
       private:
        int alpha_data;

       public:
        alpha()
           {
              alpha_data=0;
           }

        alpha(int d)
           {
              alpha_data=d;
           }

        void show()
           {
              cout<<\"\\n Value of alpha_data = \"<<alpha_data<<endl;
           }
        friend beta;
    };


 //------------------------------  beta  ---------------------------------//


 class beta
    {
       private:
        int beta_data;

       public:
        beta()
           {
              beta_data=0;
           }

        void show(alpha a)
           {
              cout<<\" Value of beta_data = \"<<a.alpha_data<<endl;
           }

    };

 main()
    {
       clrscr();

       alpha a(786);
       beta b;

       a.show();
       b.show(a);

       getch();
       return 0;
    }

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