title: Using templates to define static arrays in a class
body: <p>I thought this would be really easy, but I have yet to get this working. I want to use templates to define the size of a static unsigned char array data member of a class. I am using templates on two of my functions to define the data types being used, and that works fine. I was thinking something like this:</p>
  
  <pre><code>template&lt;unsigned S&gt;
  class Buff
  {
  private:
      static unsigned char buffer[S];
      int offset;
  public:
      pAllocBuff(){offset=0;};
      template &lt;typename T&gt;
      T* New(T, int);
      template &lt;typename T&gt;
      T* New(T);
  
  };   
  </code></pre>
  
  <p>The idea is that New(T, int) allocates memory from buffer for a data type array.</p>
  
  <p>ie: <code>char* i = myBuff.New&lt;char&gt;('\0',15); //allocate 15 byte array to i from buffer and initialized to '\0'</code></p>
  
  <p>or New(T) allocates memory from the buffer for a single data type</p>
  
  <p>ie: <code>string* j = myBuff.New&lt;string&gt;("Hello Stack Overflow!"); //allocate memory to string object j from buffer and initialize</code></p>
  
  <p>If i replace 'S' with BUFFSIZE and #define BUFFSIZE 1024*1024 (or whatever), everything works great. But i want to make it so that the size of the buffer can be defined for different instances of Buff. So, like:</p>
  
  <p><code>Buff&lt;1024*1024&gt; myBuff;</code></p>
  
  <p>When I do this, all the member functions in my class are flagged as missing template arguments, even though S has nothing to do with them. </p>
  
  <p>EDIT: I got this working with the suggestion below. I guess im confused why</p>
  
  <p>'template'</p>
  
  <p>needs to be above every function in the class, even though S is not used in that function. Is this just required because it is over the class?
  Thanks for your knowledge!</p>