Giving preference to one operator[] over another
<p>Consider the following class:</p>

<pre><code>class Test
{
public:
    Test( char );
    Test( int );
    operator const char*();
    int operator[]( unsigned int );
};
</code></pre>

<p>When I use it:</p>

<pre><code>Test t;
Test&amp; t2 = t[0];
</code></pre>

<p>I get a compiler error where it can't figure out which operator[] to use. MSVC and Gcc both. Different errors. But same problem.</p>

<p>I know what is happening. It can construct a Test from either an int or a char, and it can either use <code>Test::operator[]</code> or it can cast to const char* and use the built <code>char*[]</code>.</p>

<p>I'd like it to prefer <code>Test::operator[]</code>.</p>

<p>Is there a way to specify a preference like this?</p>

<p>UPDATE: First, I'll agree with response below that there is no language feature that lets you specify a priority for conversions. But like juanchopanza found below - you can create such a preference indirectly by making one conversion require no casts, and make the other require a cast. E.g. <code>unsigned int</code> as the argument for <code>operator[]</code> won't work but, using <code>int</code> will. </p>

<p>The default index argument is unsigned - for gcc and msvc anyway - so making the index argument unsigned will cause the compiler to prefer the right operator. </p>

<p>@Konrad: about implicit conversions to built-in types. Agree generally. But I need it in this case.</p>
