This may be a stupid question, but what is the best way to program 2 classes that share a set of variables?
- Class A and Class B both need access to int x and int y.
- If class A changes x or y, the changes should be reflected in class B
My thoughts: Class A and B can inherit Class C (which contains the variables x,y) - But this would create an instance of c for both A,B. - I only need one instance of x and y
Maybe I need friend class, or static variables?
Aucun commentaire:
Enregistrer un commentaire