/*I just started coding few days and was going through friend function in cpp and it was saying friend used out of class I can’t understand , even I used it inside the class .
*/
> `#include<iostream>
using namespace std;
class Y;
class X{
int data;
public:
void setvalue(int value){
data=value;
> }
friend void add(X , Y );
> };
class Y{
int num;
public:
void setvalue(int value){
num=value;
friend void add(X , Y);
> }
> };
void add(X o1, Y o2)//x ka o1 hai aur y ka o2 hai{
cout<<"gives-"<<o1.data+o2.num;
> };
int main(){
X a;
a.setvalue(5);
Y b;
b.setvalue(6);
add(a,b);
return 0;
> }`
New contributor
shivam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.