title: How to template two almost identical constructors
body: <p>my situation is like this:</p>
  <pre><code>// abc.h
  struct ABC{
      ABC(const std::initializer_list&lt;std::string&gt;&amp; il);
      ABC(const std::vector&lt;std::string&gt;&amp; il);
  }
  
  // abc.cpp
  ABC::ABC(const std::initializer_list&lt;std::string&gt;&amp; il){
      // do stuff
  }
  ABC::ABC(const std::vector&lt;std::string&gt;&amp; il){
      // do exactly the same stuff - body is copy&amp;paste from constructor above
  }
  
  // main.cpp
  int main(){
      ABC abc1 = {&quot;str1&quot;,&quot;str2&quot;,&quot;str3&quot;};
      std::vector&lt;std::string&gt; v = {&quot;str4&quot;,&quot;str5&quot;,&quot;str6&quot;};
      ABC abc2 = v;
  }
  </code></pre>
  <p>I thought to declare a template constructor instead of those two and instantiate the two constructors for the input param types i need:</p>
  <pre><code>// abc.h
  struct ABC{
      template &lt;typename T&gt; ABC(const T&amp; il);
  }
  template ABC::ABC&lt;initializer_list&lt;string&gt;(const initializer_list&lt;string&gt;&amp; il);
  template ABC::ABC&lt;vector&lt;string&gt;(const vector&lt;string&gt;&amp; il);
  </code></pre>
  <p>and define the template body:</p>
  <pre><code>// abc.cpp
  template &lt;typename T&gt; ABC::ABC(const T&amp; il){
      // do stuff
  }
  </code></pre>
  <p>I got compiler error.</p>
  <p>Question is: How can i reuse the code?
  or How both constructors can use the same code?</p>