Answers for "A simple example of a friend class"

0

A simple example of a friend class

#include <iostream>
using namespace std;
class A
{
   int x=4;
   friend class B; //friend class
};
class B
{
   public:
   void display (A &a)
     {
        cout<<”value of x is:” <<a.x;
     }
};
int main ()
{
   A a;
   B b;
   b. display (a);
    return 0;
}
Posted by: Guest on May-07-2021

Code answers related to "A simple example of a friend class"

Browse Popular Code Answers by Language