Imagine I have a class A and a class B that both depend on the same set of variables. Class A sets the values for the variables and uses them and when it's time, an object of class B is created where functions in class B will use and modify those variables. However, I need the modifications to not stay solely within B but to also be visible outside of the object of B.
Natively, class B would not be able to see any of class A's members. I decided to let class B inherit class A's members using class B : public A. This allows class B to access everything it needs to. Is there a better or more accepted way of doing this?
I'm also a bit confused about another thing. If an object of B is created in such a scenario, won't the object just have its own copy of A's member variables and functions, meaning that any changes will stay only within the B object and will not appear in an object of A?
Are you trying to make class-wide changes that affect all current and future instances of those objects? Then you're prob looking for static variables: