title: C++ Have two child classes share a variable from their base class
body: <p>So say I have 3 classes: Base, A, and B.</p>
  
  <p>Base is a base class for both class A and class B.</p>
  
  <p>Base has a variable val that A and B can access.</p>
  
  <p>How would I get it to work where I can set the val variable through class A, and it is reflected in class B?</p>
  
  <p>For example:</p>
  
  <p>I know this code below won't work because I am creating an OBJECT of the type a and b.</p>
  
  <p>What I want to do is to simply have a and b share the same variable so that whenever <code>a</code> does something to it, it is reflected in <code>b</code>.</p>
  
  <pre><code>a aa;
  b bb;
  
  aa.SetVal(50000);
  cout &lt;&lt; aa.GetVal() &lt;&lt; endl;
  cout &lt;&lt; bb.GetVal() &lt;&lt; endl;
  </code></pre>
  
  <p>In the end I'd want both <code>cout</code> lines to print out 50000.</p>
  
  <p><strong>EDIT: The classes A and B will be doing different operations and just need to be able to access/change the val variable in base</strong></p>