Specialization of casting operator to template argument
<p>I can't find this question answered in any other place, so I finally decided to ask.
I have a C++ templated class that includes a casting operator to the type of one of the arguments:</p>

<pre><code>template &lt;class E, class B&gt;
class bar {
    private:
        B innerVal_;
    [...]
    public:
        /* Casting to the type of the 2nd template argument */
        operator B() const { return innerVal_; }; // default implementation provided
};
</code></pre>

<p>However, I need to provide a specialization of this casting operator for some specific template arguments, for instance:</p>

<pre><code>template&lt;&gt;
bar&lt;concreteType,int&gt;::operator int() // &lt;-- whoops, error!
{ [...] } 
</code></pre>

<p>The thing is that, no matter how I specify the syntax of the casting operator, gcc consistently returns me an error referred to the declaration of the function. The most common one is:</p>

<blockquote>
  <p>error: template-id ‘operator int&lt;>’ for ‘bar&lt; concreteType, int>::operator int()’ does not match any template declaration.</p>
</blockquote>

<p>Which I got with these lines:</p>

<ul>
<li>Defining the casting operator as "operator int()"</li>
<li>Using "operator typeB()", after declaring in the original template a line "typedef B typeB;"</li>
</ul>

<p>I also played around with the "typename" keyword, with template brackets, and made some other desperate attempts. All of them result in bizarre errors --that I'm not going even to paste here.</p>

<p>Am I losing some obvious detail? Do you have any hint/pointer for me? Any help will be useful.</p>
