title: Connecting three different objects
body: <p>I asked a similar question a couple of hours ago about connecting two elements of a vector. Now, I would like to make my question more general. Let's assume that we have two objects of the type double namely <code>double d1, d2</code>. We want the third object (<code>double d3</code>) to obtain the value of <code>d1+d2</code>, such that if we change <code>d1</code> or <code>d2</code>, then <code>d3</code> automatically obtains the new value of <code>d1+d2</code>. How can we do it in C++?</p>
  
  <p>This is what I mean:</p>
  
  <pre><code>int main(){
  double d1,d2,d3;
  d1=4;
  d2=7;
  
  //some operations to make d3=d1+d2
  
  std::cout&lt;&lt;d3&lt;&lt;endl;// I want it to print 11
  d2=-4;
  std::cout&lt;&lt;d3&lt;&lt;endl;//Now without any further operations between these line, it should print 0
  return 0;     
  }
  </code></pre>
  
  <p>Thanks.</p>