Note that there are some explanatory texts on larger screens.

plurals
  1. POTemplate constructor in a class template - how to explicitly specify template argument for the 2nd parameter?
    primarykey
    data
    text
    <p>Template constructor in a class template - how to explicitly specify template argument for the 2nd parameter?</p> <p>compile error when tried to explicit specify template argument for constructor 2. How should I do it if I really want to explicit call constructor 2 ?</p> <p>Please note this is the same situation for boost::shared_ptr when you want to explicitly specify the deleter type. </p> <p>N.B. For <strong>non</strong>-construction function foo(), explicitly specify works fine.</p> <p>N.B I know it works fine <strong>without</strong> specify the 2nd one explicitly for the constructor 2 as template argument deduction normally just works fine, I am just curious how to specify it explicitly.</p> <pre><code>template&lt;class T&gt; class TestTemplate { public: //constructor 1 template&lt;class Y&gt; TestTemplate(T * p) { cout &lt;&lt; "c1" &lt;&lt; endl; } //constructor 2 template&lt;class Y, class D&gt; TestTemplate(Y * p, D d) { cout &lt;&lt; "c2" &lt;&lt; endl; } template&lt;class T, class B&gt; void foo(T a, B b) { cout &lt;&lt; "foo" &lt;&lt; endl; } }; int main() { TestTemplate&lt;int&gt; tp(new int());//this one works ok call constructor 1 //explicit template argument works ok tp.foo&lt;int*, string&gt;(new int(), "hello"); TestTemplate&lt;int&gt; tp2(new int(),2);//this one works ok call constructor 2 //compile error when tried to explicit specify template argument for constructor 2 //How should I do it if I really want to explicit call constructor 2? //TestTemplate&lt;int*, int&gt; tp3(new int(), 2); //wrong //TestTemplate&lt;int*&gt; tp3&lt;int*,int&gt;(new int(), 2); //wrong again return 0; } </code></pre>
    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.
 

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