Write a program to perform Class is a friend of another class

/*
   Class is a friend of another class
*/
#include<iostream>
using namespace std;
class Demo;

class Sample
{
    int a;
    public:
            void accept(Demo &D);
            void display(Demo &D);
};

class Demo
{
    int b;

    public:
           friend class Sample;
};


void Sample:: accept(Demo &D)
{
  cout<<"\n\n Enter two number: ";
  cin>>a>>D.b;
}
void Sample:: display(Demo &D)
{
  cout<<"\n A:"<<a;
  cout<< "\n B:"<<D.b;
}

int main()
{
    Sample s;
    Demo d;

    s.accept(d);
    s.display(d);

    return 0;
}

Previous
Next Post »