title: How can I specify a return type for operator[]?
body: <p>Is it possible to explicitly specify a return type for overloaded <code>operator[]</code>?</p>
  
  <p>For example, I have an object instance with an overloaded operator <code>[]</code>, and if I use <code>instance["num"]</code>, I'd like it to return an <code>int</code>, and <code>instance["flt"]</code> a <code>float</code> (there's already type handling logic), like this:</p>
  
  <pre><code>int some_value = instance["amount_of_entries"];
  float other_value = instance["percentage"];
  </code></pre>
  
  <p>I've tried this:</p>
  
  <pre><code>class someClass {
      template&lt;class T&gt; T&amp; operator[](char* index){ ... }
  };
  
  int val = instance["int_value"];
  </code></pre>
  
  <p>But I get an error:</p>
  
  <pre><code>error C2783: 'T &amp;CSettings::operator [](char*)' : could not deduce template argument for 'T'
  </code></pre>
  
  <p>I thought of using <code>instance&lt;int&gt;["int_value"]</code>, but that's a syntax error and doesn't compile.</p>