I want to assign a value to the variable x which belongs to the class X using friend function.
Is there any way to assign a value, say 30 to the variable x using the friend function.
I tried the following code but the output is different.
#include <iostream>
#include <conio>
class X
{
int x;
public:
void showdata()
{
cout<<"x ="<<x<<endl;
}
friend void putvalue(X a);
};
void putvalue(X a)
{
a.x=30; //
}
int main()
{
X test;
putvalue(test);
test.showdata();
getch();
return 0;
}