title: How to take a typename as a parameter in a function? (C++)
body: <p>I need to be able to pass a typename as a parameter:</p>
  
  <pre><code>int X = FileRead(file, 9, char);
  </code></pre>
  
  <p>The concept is for FileRead(std::fstream, int pos, ???) to read pos*sizeof(whatever the type is) to get the desired position.  I tried templates:</p>
  
  <pre><code>template&lt;typename T&gt;
  T FileRead(std::fstream file, int pos, T type)
  {
      T data;
      file.read(reinterpret_cast&lt;char*&gt;(&amp;data), sizeof(data));
      return data;
  }
  </code></pre>
  
  <p>but that required that I create a variable of the type to use every time I wanted to use FileRead, and I really don't feel like redesigning an entire program just because of one function, so is there anyway to use a typename as a parameter?</p>