title: one to one association
body: <p>What is the best way to represent one-to-one object association in C++? It should be as automatic and transparent as possible meaning, that when one end is set or reset, the other end will be updated. Probably a pointer-like interface would be ideal:</p>
  
  <pre><code>template&lt;typename AssociatedType&gt;
  class OneToOne{
      void Associate(AssociatedType &amp;);
      AssociatedType &amp;operator* ();
      AssociatedType *operator-&gt;();
  } 
  </code></pre>
  
  <p>Is there any better way to do it or is there any complete implementation?</p>
  
  <p>EDIT:</p>
  
  <p>Desired behavior:</p>
  
  <pre><code>struct A{
      void Associate(struct B &amp;);
      B &amp;GetAssociated();
  };
  
  struct B{
      void Associate(A &amp;);
      A &amp;GetAssociated();
  };
  
  A a, a2;
  B b;
  
  a.Associate(b);
  // now b.GetAssociated() should return reference to a
  
  b.Associate(a2);
  // now b.GetAssociated() should return reference to a2 and 
  // a2.GetAssociated() should return reference to b
  // a.GetAssociated() should signal an error
  </code></pre>