/* */ Click to Join Live Class with Shankar sir Call 9798158723

What is Friends as Bridge ?

There are two classes. the private data members of those two classes need to be accessed or modified simultaneously using a common function. then this function should be declared as a friend to both the classes. when using friend function we can bridge the two unrelated classes.

Q1.) Example of Friends as Bridge .
    #include < iostream.h>

class friendcl



int a,b;


friend int sum ( friendcl x);

void set( int w, int q);


void friendcl:: set( int w, int q)


a= w;



int sum (friendcl x)


return x.a + x.b;


int main()


friendcl r;


cout << " sum of the values is::" << sum (r);

return 0;


sum of the values is::10