Hi I'm having some trouble understanding the friend keyword from C++
Let's say i have a class as shown below:
class A
{
private:
friend class B;
struct Astruct
{
int funVar = 1;
};
Astruct myStruct
public:
changeAStruct(); // changes the value of funVar to 2
};
class B
{
//how do i here get access to myStruct with the value 2?
};
Hopefully the pseudo code above will show you my problem. I want the same instance of myStruct that using the this pointer would get me in class A in class B. How can I achieve this?
What I don't want is typing this in class B:
A::Astruct myStruct
As this would create a new struct in class B with the funVar being set to 1. I want the same struct in class A, but now in class B...
EDIT: I suppose that from main i can send the myStruct into class B as a reference and access it from there. Is this an optimal thing to do?