To access personal data of class we use the friend function. The friend function is not the member of the class but still, we can access its members. For calling the friend function you have to make an object.
#include<iostream.h> #include<conio.h> class A { friend void show(A); int a; public: A() { a=100; } }; void show(A t1) { cout << t1.a; } void main() { A a1; clrscr(); show(a1); getch(); } Output: 100
#include<iostream.h> #include<conio.h> class B; class A { friend void show(A,B); int a; public: A() { a=100; } }; class B { friend void show(A,B); int b; public: B() { b=200; } }; void show(A t1,B t2) { cout << t1.a + t2.b; } void main() { A a1; B b1; clrscr(); show(a1,b1); getch(); } Output: 300