I tried to realize the friend class to provide the members's value for the member of another class.
I' ve tried to make the object of class Friend
and defined it as Attempt
's argument and after replace &Friend::fri
to object.fri()
but it was not compiled also.
class Friend {
public:
int val = 0;
int fri() {
val = 456;
return val;
}
friend class Partner;
};
class Partner {
public:
//(corrected) Friend Object;
int Attempt() {
std::cout << "The value from the friend class: " <<
&Friend::fri /*(corrected) Object.fri()*/<<"\n"; // '&' was requred by compiler to make pointer to
//the member
return 0;
}
};
I expected Attempt
to write the value from fri()
. But there's 1 and I can't undertand where is this 1 from.