Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Edit:</strong> this is a correct answer to a different question.</p> <p>Using the typename <code>T</code> twice confuses the issue a little, because they are compiled separately and are not connected in any way.</p> <p>You can overload the method to take a templated parameter:</p> <pre><code>template &lt;typename T&gt; class MyTemplateClass { void DoSomething(T&amp; t) { } template &lt;typename U,typename V&gt; void DoSomething(SomeRandomClass&lt;&lt;U,V&gt;&amp; r) { } }; </code></pre> <p>This maps <code>U</code> and <code>V</code> in the new method to <code>T'</code> and <code>S'</code> in <code>SomeRandomClass</code>. In this setup, either <code>U</code> or <code>V</code> could be the same type as <code>T</code>, but they don't have to be. Depending on your compiler, you ought to be able to do</p> <pre><code>MyTemplateClass&lt;string&gt; mine; SomeRandomClass&lt;int,double&gt; random; // note: nevermind the non-const ref on the string literal here... mine.DoSomething("hello world"); mine.DoSomething(random); </code></pre> <p>and the templated call will be selected as the matching overload without having to respecify the types explicitly.</p> <p><strong>Edit:</strong></p> <p>To do with with template specialization makes no difference to the overload of <code>DoSomething</code>. If you specialize the class as follows</p> <pre><code>template &lt;&gt; class SomeRandomClass &lt;int,double&gt; { // something here... }; </code></pre> <p>then the overload above will eat up this specialized implementation gladly. Just be sure the interfaces of the specialized template and the default template match.</p> <p>If what you're wanting is to specialize <code>DoSomething</code> to take a specific pair of types for <code>SomeRandomClass</code> then you've already lost generality...that's what specialization is.</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.
    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