title: C++ Templates: Pass Type, not instance?
body: <p>Templates may not be the answer here but I tried some inheritance and that didn't work so here is where I am at.</p>
  
  <p>The Problem:</p>
  
  <p>I have an abstract base class that houses all my "work" functions. I'll then have a bunch of other classes that extend that base class and essentially just fill in the details of the data to pass down into the "work" functions as well as overriding a couple of the base classes functions.</p>
  
  <p>One of the main pieces of data that will change in each derived class is a struct. </p>
  
  <p>So my initial plan of attack was to have a BaseStruct defined and the abstract base class just did all of it's work on that base struct. If the derived classes used a different struct that extended that base struct then that's fine.</p>
  
  <p>The problem I ran into with this is that I couldn't get the size of the struct since in the work function the type of the struct it was operating on is a BaseStruct rather than the derived type.</p>
  
  <p>So now I'm looking at templates.</p>
  
  <p>Essentially I want to have a Base function that does this:</p>
  
  <pre><code>template&lt;typename StructType&gt;
  void AbstractMaterial::CreateVertexBuffer() {
  
      StructType* array = new StructType[numVertices];
  
      size_t si = sizeof(StructType) * numVertices;
  
      ...
  }
  </code></pre>
  
  <p>Of course without actually passing anything into this function, it doesn't really work. I'd rather not create an instance of StructType to pass in just to get the type information but it doesn't seem like there is any other way?</p>
  
  <p>Essentially I want derived classes to someone specify a StructType to use when this function is called.</p>
  
  <p>Thanks!</p>