title: C++ : Allocation of an array attribute in a class
body: <p>I would like to know, if I have a class with an array attribute whose size is not the same for all instances :</p>
  
  <pre><code>class myObject{
  
  private:
      int size;
      int* array;
  
  // other methods/attributes
  
  };
  </code></pre>
  
  <p>Is it obligatory allocated using new ?</p>
  
  <pre><code>explicit myObject(int size = 0):size(size){
      array = new int[size];
  }
  </code></pre>
  
  <p>Even if in the main(), I always use constant parameters to create the instances of the class ? (Meaning I know every array size at compile time).</p>
  
  <pre><code>int main{
      myObject object (5);
      return 0;
  }
  </code></pre>
  
  <p>Apparently something like :</p>
  
  <pre><code>private:
      int size;
      int array[size];
  </code></pre>
  
  <p>wont work, no ?</p>
  
  <p>That means that array attribute whose size are not constant of the class are obligatory on the heap ?</p>
  
  <p>Thank you for your answers,</p>