title: Any way to initialize this variable based on class template type?
body: <p>I have a class <code>stats</code> with a template so that it can be flexible. I'm new to templates though, and I thought the point of them was to make it flexible around the user. So I feel like I'm doing something wrong seeing as I've hit a small wall.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdio&gt;
  #include &lt;iomanip&gt;
  
  template &lt;typename T&gt;
  class stats
  {
      private:
          int n;
          T sum;
      public:
          stats()
          {
              this-&gt;n = 0;
              this-&gt;sum = T();
          }
          void push(T a);
          void print();
  };
  
  int main()
  {
      std::string tmp; // change type based on class type T
      stats&lt;std::string&gt; s;
      while (std::cin &gt;&gt; tmp) // while input is active...
      {
          s.push(tmp);
      }
  
      // Output &amp; Formatting
      s.print();
      return 0;
  }
  template &lt;typename T&gt;
  void stats&lt;T&gt;::push(T a)
  {
      this-&gt;sum += a;
      ++this-&gt;n;
  }
  template &lt;typename T&gt;
  void stats&lt;T&gt;::print()
  {
      std::cout   &lt;&lt; std::left &lt;&lt; std::setw(4) &lt;&lt; &quot;N&quot;   &lt;&lt; &quot;= &quot; &lt;&lt; n   &lt;&lt; '\n'
                  &lt;&lt; std::left &lt;&lt; std::setw(4) &lt;&lt; &quot;sum&quot; &lt;&lt; &quot;= &quot; &lt;&lt; sum &lt;&lt; '\n';
  }
  </code></pre>
  <p>From <code>int main()</code>, ideally, I'd like tmp to not have to be changed by myself every time I wan to try a different type. Is that possible in C++?</p>