Program to implement the concept of Friend class in c++
1.Open your turbo c++ compiler and start a new program.
2. Copy the given code in your program
#include<iostream.h>
#include<conio.h>
class A
{
private: void show()
{
cout<<"\n This is a private function of class A";
}
friend class B;//Making class B as friend of A
};
class B
{
public: void display()
{
A obj1; //Making object of class A
obj1.show(); //Accessing private member function
// of class A in Friend class B
}
};
void main()
{clrscr(); //Main Program
B obj;
obj.display(); //calling display of class B
// which is calling show of A
getch();
}
No comments:
Post a Comment