title: How do I share class members, safely?
body: <p>I'm struggling to organise a program. I have a class <code>Solver</code>, which looks like this:</p>
  
  <pre><code>class Solver {
     ...
     VarOrder order;
     ...
     vector&lt;Constraint&gt; watches;
     vector&lt;Constraint&gt; undos;
     ...
  };
  </code></pre>
  
  <p>Where of course <code>Solver</code> uses these members to its business. However, <code>VarOrder</code> also needs to use <code>watches</code> and <code>undoes</code> to do <em>its</em> business and both classes need to be able to see each other's modifications. So it seems like I need to pass a pointer to the <code>watches</code> and <code>undoes</code> member variables into the constructor of <code>VarOrder</code>. I guess I should do that with <code>shared_ptr</code> to be safe, but pointers to vectors seems like opening a massive can of awful.</p>
  
  <p>I could also use the "friends" feature of C++, but that seems wrong as well, since <code>VarOrder</code> only requires access to two of <code>Solver</code>'s members, not all of them, which seems like it would be weird design.</p>
  
  <p>Probably my class design is wrong, but short of creating global data, I don't know how to reorganize this. Any advice appreciated.</p>
  
  <p>Thank you.</p>