vendredi 6 avril 2018

C++ Design: How do I set up two classes that share a set of variables?

This may be a stupid question, but what is the best way to program 2 classes that share a set of variables?

  1. Class A and Class B both need access to int x and int y.
  2. 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