title: template function within non template class does not link
body: <p>I can not link template functions within non template class
  I have:</p>
  
  <pre><code>class base {};
  class mgr : base
  {
      template function a;
      ........
      non template functions
  };
  </code></pre>
  
  <p>template a access variables of class <code>m</code>
  for example</p>
  
  <pre><code>static m&lt;T&gt;* ptr;
  ptr = reinterpret_cast&lt;m&lt;T&gt;*&gt;( std::get&lt;0&gt;(d) );
  ptr-&gt;m&lt;T&gt;::clear();
  (m private section is friend of mgr)
  </code></pre>
  
  <p>in class <code>g</code> I want to use function <code>a</code></p>
  
  <pre><code>static mgr mg; 
  mgr *p = &amp;mg;
  
  m&lt;T&gt; v = *( reinterpret_cast&lt;T*&gt;( p-&gt;a(p1,p2) );
  note that func. a() return pointer to base (similar idea to void*) regardless of &lt;T&gt;
  </code></pre>
  
  <p>at the end of <code>m.cpp</code> I have (per specialization)
  example:    </p>
  
  <pre><code>template class m&lt;string&gt;;
  </code></pre>
  
  <p>at the end of <code>mgr.cpp</code> I have (per specialization)
  example: </p>
  
  <pre><code>template pbase mgr::a&lt;string&gt;( ... );
  </code></pre>
  
  <p>hpp files used for declarations, 
  cpp files for definition (implementation)</p>
  
  <p>watching the link map I can see that <code>mgr</code> linked template specialized 
  function <code>a</code>
  however it failed to link it in <code>g</code></p>
  
  <p>any help would be appreciated</p>
  
  <p>here is more code 
  mgr.hpp</p>
  
  <pre><code>#ifndef __mgr__mgr___
  #define __mgr__mgr___
  
  #include &lt;iostream&gt;         // cout
  #include &lt;ostream&gt;         // cout
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;map&gt;
  #include &lt;tuple&gt;
  #include &lt;type_traits&gt;
  
  #include &lt;limits&gt;
  #include &lt;climits&gt;
  #include &lt;exception&gt;
  
  
  
  using namespace std;
  
      typedef string tInstName;
      enum  tInstType { Typ1 , Typ2 , Typ3 };
  
  
      class mgr
      {
          public:
          class MIObase {};
  
          map&lt;string,tuple&lt;MIObase*,string,tInstType&gt;&gt; Imap;
          template &lt;class T&gt; MIObase* getInstance (  const string&amp; name , const iName&amp; instname  );
  
      };
  #endif
  </code></pre>
  
  <p>mgr.cpp</p>
  
  <pre><code>#include &lt;ostream&gt;     
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;     
  #include &lt;string.h&gt;
  #include &lt;errno.h&gt;
  
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;map&gt;
  #include &lt;set&gt;
  #include &lt;algorithm&gt;
  #include &lt;utility&gt;   
  #include &lt;tuple&gt;   
  #include &lt;type_traits&gt;
  #include &lt;typeinfo&gt;
  
  #include &lt;limits&gt;
  #include &lt;climits&gt;
  #include &lt;exception&gt;
  
  
  #include "mgr.hpp"
  #include "mfunc.hpp"
  
  using namespace std;
  
          template&lt;&gt;
          pMIObase mgr::getInstance&lt;string&gt; (  const string&amp; filename , const string&amp; name )
          {
  
              tuple&lt;pMIObase,string,tInstType&gt; d;
              static mfunc&lt;string&gt;* ptr;
              static pMIObase ptr_;
  
  
              auto it = Imap.find ( instname );
              if ( it != Imap.end() ) 
              {
                  d=Imap[instname];
                  ptr = reinterpret_cast&lt;mfunc&lt;string&gt;*&gt;( std::get&lt;0&gt;(d) );
                  ptr-&gt;mfunc&lt;string&gt;::clear();
                  ptr_ = std::get&lt;0&gt;(d);
                  cout&lt;&lt;instname &lt;&lt;" already exists .......\n";
                  return ptr_;
              }
              else
              {
                  //mfunc&lt;string&gt; I;
                  ptr = new mfunc&lt;string&gt;;
  
  
                  d = make_tuple (reinterpret_cast&lt;pMIObase&gt;(ptr),name,Tstr);
                  Imap[instname] = d;
  
                  ptr-&gt;clear();
                  ptr_ = reinterpret_cast&lt;pMIObase&gt;(ptr);
                  return ptr_;
              }
          }
  
  
      template pMIObase mgr::getInstance&lt;string&gt;(const string&amp; filename , const tInstName&amp; instname);
  </code></pre>
  
  <p>g.cpp </p>
  
  <pre><code>#include "mgr.hpp"
  
  using namespace std;
  
  void g()
  {
      static mgr mb;
      mgr *pMIO=&amp;mb;  
  
      // this one dose not link
      static mfunc&lt;string&gt; &amp;v =  *( reinterpret_cast&lt;mfunc&lt;string&gt;*&gt;( pMIO-&gt;mgr::getInstance&lt;string&gt; (  ) ));
  }
  </code></pre>