title: Overloading bracket assignment in C++
body: <p>I am in the process of porting an Objective-C application to C++ and I decided to create a class similar to NSObject and NSDictionary. If you are unfamiliar with this system, an NSObject is an object which all objects inherit form in Obj-C and then there is a reference counting mechanism within it. When there are no more references, the object frees itself.</p>
  
  <p>In my code, I would like to be able to do the following</p>
  
  <pre><code>CMDictionary["Key"] = Object;
  </code></pre>
  
  <p>Internally, this is stored as </p>
  
  <pre><code>Map&lt;string, CMObject*&gt; mDictionary
  </code></pre>
  
  <p>Whenever a new object is assigned into the object, the dictionary must then retain this object by calling its retain function as well as calling release on any object that this new object might have replaced. My problem stems from the fact that I cannot find anyway to run code and determine when the brackets are being used in an assignment as I would not want the retain function to be called when I wrote something like</p>
  
  <pre><code>CMDicionary["key"]-&gt;StringValue();
  </code></pre>
  
  <p>Would there by anyway to do this, or would I need to just use getter/setter functions to modify my dictionary</p>