title: Designing template class with generic private member
body: <p>I suppose some other folks ran into this design issue before so I hope someone could give me some advice on what to do: I have a class that is supposed to hold a private generic object. As far as I can tell, I can't get away without making the entire class a template. FINE. But now, is there any way to infer the type of the underlying object during construction from the constructor parameter, without explicitly specifying it (I want to omit the template parameter, <code>Derived</code>, when I instantiate the <code>Test</code> class):</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template &lt;typename T&gt;
  class Generic
  {
  };
  
  class Derived : public Generic&lt;int&gt;
  {
  public:
      Derived ();
      int GetFoo ();
  private:
      int m_foo;
  };
  
  template &lt;typename T&gt;
  class Test
  {
  public:
      Test (T &amp;underlying);
  private:
      T m_underlying;
  };
  
  Derived::Derived ()
  {
      this-&gt;m_foo = 666;
  }
  
  int Derived::GetFoo ()
  {
      return this-&gt;m_foo;
  }
  
  template&lt;typename T&gt;
  Test&lt;T&gt;::Test (T &amp;underlying) : m_underlying(underlying)
  {
      std::cout &lt;&lt; this-&gt;m_underlying.GetFoo() &lt;&lt; std::endl;
  }
  
  int main ()
  {
      Derived underlying;
      Test&lt;Derived&gt; test(underlying);
  
      return 0;
  }
  </code></pre>
  
  <p>Is there any other design strategy that I should be aware of, in order to achieve my goal?</p>