title: Replacing realloc (C --> C++)
body: <p>In an earlier question, I asked about typecasting pointers, but was directed to the better solution of using the C++ allocation system instead of mallocs. (I am converting some C code to C++)</p>
  
  <p>However, I still have an issue with a similar function:</p>
  
  <p>I changed:</p>
  
  <pre><code>tmp = malloc(sizeof(char*) * mtmp); --&gt; tmp = new char*[mtmp];
  </code></pre>
  
  <p>and</p>
  
  <pre><code>free(tmp) --&gt; delete [] tmp;
  </code></pre>
  
  <p>However, what do I do with realloc in the following function:</p>
  
  <pre><code>char* space_getRndPlanet (void)
  {
     int i,j;
     char **tmp;
     int ntmp;
     int mtmp;
     char *res;
  
     ntmp = 0;
     mtmp = CHUNK_SIZE;
     //tmp = malloc(sizeof(char*) * mtmp); &lt;-- replaced with line below
     tmp = new char*[mtmp];
     for (i=0; i&lt;systems_nstack; i++)
        for (j=0; j&lt;systems_stack[i].nplanets; j++) {
           if(systems_stack[i].planets[j]-&gt;real == ASSET_REAL) {
              ntmp++;
              if (ntmp &gt; mtmp) { /* need more space */
                 mtmp += CHUNK_SIZE;
                 tmp = realloc(tmp, sizeof(char*) * mtmp); &lt;--- Realloc
              }
              tmp[ntmp-1] = systems_stack[i].planets[j]-&gt;name;
  </code></pre>
  
  <p>I am getting the following error:</p>
  
  <pre><code>error: invalid conversion from 'void*' to 'char**'|
  </code></pre>
  
  <p>EDIT 2:</p>
  
  <p>Okay, the consensus I am getting is that I should ditch my current solution (which I am open to doing).</p>
  
  <p><strong>Just to make sure that I am understanding correctly, do you guys mean that, instead of an array of pointers to objects, I should just have a vector containing the objects themselves?</strong></p>