title: How do conversion operators work in C++?
body: <p>Consider this simple example:</p>
  
  <pre><code>template &lt;class Type&gt;
  class smartref {
  public:
      smartref() : data(new Type) { }
      operator Type&amp;(){ return *data; }
  private:
      Type* data;
  };
  
  class person {
  public:
      void think() { std::cout &lt;&lt; "I am thinking"; }
  };
  
  int main() {
      smartref&lt;person&gt; p;
      p.think(); // why does not the compiler try substituting Type&amp;?
  }
  </code></pre>
  
  <p>How do conversion operators work in C++? (i.e) when does the compiler try substituting the type defined after the conversion operator?</p>