Note that there are some explanatory texts on larger screens.

plurals
  1. POArgument conversion in the presence of function templates
    primarykey
    data
    text
    <p>I have a set of function templates that depend on two integers. These need to be instantiated, except that one of the function arguments needs to be converted. A conversion operator is provided for the purpose. However the compiler (VS 2013 express preview) refuses to recognize the possibility of conversion. See the code below.</p> <p>In conversion_op.h </p> <pre><code>template&lt;int N&gt; class Proxy { }; template&lt;int M, int N&gt; void func(const Proxy&lt;M&gt;&amp; p1, const Proxy&lt;N&gt;&amp; p2) { } typedef Proxy&lt;1&gt; SpecialProxy; class Orig { SpecialProxy P; public: operator SpecialProxy() const { return P; } }; </code></pre> <p>In conversion_op.cpp </p> <pre><code>#include "conversion_op.h" //template void func(const SpecialProxy&amp;, const SpecialProxy&amp;); //template void func(const SpecialProxy&amp;, const Proxy&lt;2&gt;&amp;); //template void func(const Proxy&lt;2&gt;&amp;, const SpecialProxy&amp;); //template void func(const Proxy&lt;2&gt;&amp;, const Proxy&lt;2&gt;&amp;); int Test() { Orig a; SpecialProxy p1; Proxy&lt;2&gt; p2; func&lt;1,1&gt;(a, p1); //OK func&lt;1,2&gt;(a, p2); //OK func&lt;1,1&gt;(p1, a); //OK func&lt;2,1&gt;(p2, a); //OK func(a, p1); //Error func(a, p2); //Error func(p1, a); //Error func(p2, a); //Error } </code></pre> <p>The error is: "could not deduce template argument for 'const Proxy &amp;' from 'Orig'. Please see declaration of func."</p> <p>I tried replacing</p> <pre><code>operator SpecialProxy() const; </code></pre> <p>by</p> <pre><code>operator const SpecialProxy&amp;() const; </code></pre> <p>but the error remains the same.</p> <p>Also tried explicitly instantiating the needed function (commented out code in conversion_op.cpp), but no luck.</p> <p>Any insight is appreciated. Thank you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload