title: Unable to dynamically set array size for struct variables
body: <p>Both sections of code below are drastically simplified, isolated versions of my actual code. The examples are just big enough to illustrate the problem. The first section of code below works fine. The section section is an attempt to begin to make it part of a class. The challenge is to make it so the maxSize variable can be set by the user at runtime in a constructor as opposed to being a hard-coded value. To add to that, I'm looking for the solution that allows me to only have to change how the struct is declared and change what is done inside the Initialize() method (which will eventually be the class constructor). I've already wasted several hours making changes that required changes to the other 50+ methods which has never worked out so I'm wondering if there is a solution I missed that doesn't require changing the other 50+ methods.</p>
  
  <p>Working code:</p>
  
  <pre><code>#include &lt;cstdio&gt;
  #include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  
  using std::cout;
  using std::endl;
  
  const int maxSize = 3;
  Node *root;
  
  struct Item{
      string key;
      string value;
  };
  
  struct Node{
      int count;
  
      Item key[maxSize + 1];
      Node *branch[maxSize + 1];
  };
  
  /* 
  -------
     ^
     |
  50+ of other methods, all using these structs as pointers, 
  pointers to pointers, &amp; references.
     |
     v
  -------
  */
  
  int main(int argc, char *argv[])
  {
  
      return 0;
  }
  </code></pre>
  
  <p>An example of just one attempt to very gradually modify the code as a whole toward becoming a class:</p>
  
  <pre><code>#include &lt;cstdio&gt;
  #include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using std::cout;
  using std::endl;
  using std::string;
  
  int maxSize;
  Node *root;
  
  struct Item{
      string key;
      string value;
  };
  
  struct Node{
      int count;
      Item *item;
      Node *branch;
  
      // doesn't work because it requires 
      // modification of the rest of the code
      // which has only resulted in an infinite loop of debugging
      void init(int size)
      {       
          item = new Item[size]; 
          branch = new Node[size]; 
      }
  };
  
  void Initialize(int size)
  {
      maxSize = size;
  }
  
  /* 
  -------
     ^
     |
  50+ other methods, all using these structs as pointers, 
  pointers to pointers, &amp; references.
     |
     v
  -------
  */
  
  
  int main(int argc, char *argv[])
  {
      Initialize(5);
  
      return 0;
  }
  </code></pre>