Precedence between conversion operators in C++
<p>During parameter resolution for a function which expects a pointer, why is the the reference-to-pointer conversion being selected rather than the pointer conversion?</p>

<pre><code>template&lt;typename T&gt;
  class resource_ptr
  {
    public:
      operator T*()const {...} // &lt;- C1: Convert to raw pointer for observation.
      operator T*&amp;()     {...} // &lt;- C2: Convert to reference to pointer, for assignment.
    ...
  };
...
void AcquireResource(resource_class *&amp;);  // Assigns to the given pointer.
void UseResource(resource_class *);
...
resource_ptr&lt;resource_class&gt; rpResource;
AcquireResource(rpResource); // &lt;- Calls C2, as expected.
UseResource(rpResource);     // &lt;- Calls C2.  C1 would have been nice.

UseResource((resource_class*)rpResource); // &lt;- Still calls C2. ???
</code></pre>

<p>Note that in this particular design, since C2 is granting write access, it asserts that the resource pointer is currently unassigned, to prevent resource leaks.  So it's important that C2 only get used when we actually want the pointer by reference, as when passing to an API which assigns to it.  As it stands, this design is broken.</p>

<p>(These conversions can be replaced with explicit functions, but I would like to understand this issue.)</p>
