title: C++ initializing template class
body: <p>I'm somewhat baffled as to what is happening when I create my template class. I'm trying to set the capacity of the member vector_ to 50 (only once) during construction, but it seems the capacity is never properly set, so obviously I do not understand how this is supposed to be done. I've included the relevant snippets of code, as well as the console output. Thank you for your help!</p>
  
  <p>Template class for vector:</p>
  
  <pre><code>template &lt;typename T&gt;
  class V
  {
    public:
      V()
      {
        std::cout &lt;&lt; "capacity 1 = " &lt;&lt; this-&gt;vector_.capacity() &lt;&lt; "\n";
      };
      V(int capacity)
      {
        this-&gt;vector_.reserve(capacity);
        std::cout &lt;&lt; "capacity 2 = " &lt;&lt; this-&gt;vector_.capacity() &lt;&lt; "\n";
      };
      int capacity() const { return this-&gt;vector_.capacity(); };
    private:
      std::vector&lt;T&gt; vector_;
  };
  </code></pre>
  
  <p>Constructor of R where it is initialized:</p>
  
  <pre><code>R::R()
  {
    std::cout &lt;&lt; "capacity 0 = " &lt;&lt; this-&gt;s_.capacity() &lt;&lt; "\n";
    this-&gt;s_ = V&lt; std::vector&lt; std::complex&lt;float&gt; &gt; &gt;(50);
    std::cout &lt;&lt; "capacity 3 = " &lt;&lt; this-&gt;s_.capacity() &lt;&lt; "\n";
  };
  </code></pre>
  
  <p>Header of R class:</p>
  
  <pre><code>class R
  {
    public:
      R();
    private:
      V&lt; std::vector&lt; std::complex&lt;float&gt; &gt; &gt; s_;
  };
  </code></pre>
  
  <p>Output to console:</p>
  
  <pre><code>capacity 1 = 0
  capacity 0 = 0
  capacity 2 = 50
  capacity 3 = 0
  </code></pre>