How to force a template code creation without creating object instance?
<p>I have a template class that is only valid for couple of template parameters:</p>

<p>doIt.h:</p>

<pre><code>// only int and float are valid T
template &lt;typename T&gt;
class doer
{
public:
   void doIt();
}
</code></pre>

<p>I want to hide the implementation inside the .cpp file (for faster compile and also because its proprietary):</p>

<p>doIt.cpp:</p>

<pre><code>template &lt;&gt;
void doer&lt;T&gt;::doIt()  {  /* how to do it */ }
</code></pre>

<p>... and use it as follows: use.cpp:</p>

<pre><code>int main( int, char** )
{
   doer&lt;int&gt;::doIt()
}
</code></pre>

<p>The above fails to link because the implementation of void doer::doIt(void) was never in scope at the place where it was called.</p>

<p>I can force the code to be generated into doItv2.obj, as follows:</p>

<p>doIt_v2.cpp:</p>

<pre><code>template &lt;&gt;
void doer&lt;T&gt;::doIt()  {  /* how to do it */ }

doer&lt;int&gt; a;    
doer&lt;real&gt; b;
</code></pre>

<p>but this causes a variety of headaches (dynamic memory allocation before main is entered) and I actually don't want to make an instance -- I just want the object code for the template instantiations to be generated.</p>

<p>Any ideas?</p>
