I have two classes, A and B like this :
class A
{
public:
A(int i)
{
this->i = i;
}
private:
int i;
};
class B
{
public:
B()
{
i = 0;
a = new A(i);
i++;
// i = 1
// a->i must be 1
}
private:
A* a;
int i;
};
I tri to share a member between the two objects.
I want when i is modified in B, i have to be modified in A.
How can I doing something like that ? It is possible by reference ?
I hope I was clear.
Thanks.
Yes, it’s possible by reference, but then you run into scoping issues.
You can also have a
std::shared_ptrto share variables between classes.