Can we access updated public variable of one class in another class without inheritance. Just like below.
This class A which have public int variable x. In updateValue function i have updated x value.
class A
{
public:
int x;
A()
{
x=0;
}
void updateValue()
{
for(int i=1; i<=5; i++)
{
x++;
}
}
};
Now I want to access this updated x value in another class without using inheritance.
class B
{
public:
void getVal()
{
cout<<"Valuse of x is : "<<x <<endl;
}
};
Anyone please help ! I need this functionality to use in my project but I can't use inheritace becuase class A and class B are already two separate child classes.