title: Declaring an array inside a class, and setting its size with the constructor
body: <p>I haven't worked with c++ in a while, but I just started a project with it. This may not be possible, but Im trying to create a template class with an array that sets its size to the value of a constant which i'm trying to set with the constructor. </p>
  
  <p>This is the code of the constructor:</p>
  
  <pre><code>Tarray(int s): start_size(s){
      }
  </code></pre>
  
  <p>This is the code that sets the array size:</p>
  
  <pre><code>const int start_size;
  T this_array[start_size];
  </code></pre>
  
  <p>This is the entire file:</p>
  
  <pre><code>#ifndef TARRAY_H_
  #define TARRAY_H_
  
  
  template&lt;typename T&gt;
  class Tarray {
  private:
      const int start_size;
      T this_array[start_size];
      int array_size;
  public:
      Tarray(int s): start_size(s){
      }
      ~Tarray(){
          delete[] this_array;
      }
      T &amp; operator[](int i){
          return this_array[i];
      }
  };
  
  
  
  #endif /* TARRAY_H_ */
  </code></pre>
  
  <p>These are the errors I get:</p>
  
  <pre><code>..\/template_array/Tarray.h:16:24: error: 'Tarray&lt;T&gt;::start_size' cannot appear in a constant-expression
  ..\/template_array/Tarray.h:16:34: error: 'new' cannot appear in a constant-expression
  ..\/template_array/Tarray.h:16:34: error: ISO C++ forbids initialization of member 'this_array' [-fpermissive]
  ..\/template_array/Tarray.h:16:34: error: making 'this_array' static [-fpermissive]
  ..\/template_array/Tarray.h: In instantiation of 'Tarray&lt;Person&gt;':
  ..\Human.cpp:17:24:   instantiated from here
  ..\/template_array/Tarray.h:16:34: error: invalid in-class initialization of static data member of non-integral type 'Person*'
  Build error occurred, build is stopped
  Time consumed: 343  ms. 
  </code></pre>
  
  <p>The error messages have been changing as I try to tweak the code, but these are the errors from this particular build. </p>
  
  <p>Thanks for any help</p>