title: C++ class with template member variable
body: <p>I am trying to solve a programming problem that consists of an object (call it Diagram), that contains several parameters. Each parameter (the Parameter class) can be one of several types: int, double, complex, string - to name a few.</p>
  
  <p>So my first instinct was to define my Diagram class as having a vector of template parameters, which would look like this.</p>
  
  <pre><code>class Diagram
  {
  private:
      std::vector&lt;Parameter&lt;T&gt; &gt; v;
  };
  </code></pre>
  
  <p>This doesn't compile, and I understand why. So, based on the recommendations on this page <a href="https://stackoverflow.com/questions/6261375/how-to-declare-data-members-that-are-objects-of-any-type-in-a-class">How to declare data members that are objects of any type in a class</a>, I modified my code to look like:</p>
  
  <pre><code>class ParameterBase
  {
  public:
      virtual void setValue() = 0;
      virtual ~ParameterBase() { }
  };
  
  
  template &lt;typename T&gt;
  class Parameter : public ParameterBase
  {
  public:
      void setValue() // I want this to be 
                      // void setValue(const T &amp; val)
      {
          // I want this to be 
          // value = val;
      }
  
  private:
      T value;
  };
  
  class Diagram
  {
  public:
      std::vector&lt;ParameterBase *&gt; v;
      int type;
  };
  </code></pre>
  
  <p>I'm having trouble figuring out how to call the setValue function with an appropriate templated parameter. It is not possible to have a templated parameter in the ParameterBase abstract base class. Any help is greatly appreciated.</p>
  
  <p>P.S. I don't have the flexibility to use boost::any. </p>