title: Writing variadic template constructor
body: <p>Recently I asked <a href="https://stackoverflow.com/questions/28864200/how-to-set-the-same-type-for-all-arguments-in-this-example/28864581#28864581">this</a> question but now I would like to expand it. I wrote the following class:</p>
  
  <pre><code>template &lt;class T&gt;
  class X{
  public:
      vector&lt;T&gt; v;
      template &lt;class T&gt;
      X(T n) {
          v.push_back(n);
      }
      template &lt;class T, class... T2&gt;
      X(T n, T2... rest) {
          v.push_back(n);
          X(rest...);
      }
  };
  </code></pre>
  
  <p>When creating an object using </p>
  
  <pre><code>X&lt;int&gt; obj(1, 2, 3);  // obj.v containts only 1
  </code></pre>
  
  <p>Vector only contains the first value, but not others. I've checked and saw that constructor is called 3 times, so I'm probably creating temp objects and filling their vectors with the rest of the arguments. How do I solve this problem?</p>