title: Nested Struct and Array C++
body: <p>Hello I am dealing with nested structs and arrays in C++, here is some background info:</p>
  
  <pre><code> struct Cells // a collection of data cells lines 
  
       cells :: [Cell] // the cells: a location and a value 
  
       nCells :: Integer // number of cells in the array
  
       capacity :: Integer // maximum size of the array end 
  
  
  
  struct Cell 
        location :: int // a location of data cells lines 
        value :: int // the value end Cells
  </code></pre>
  
  <p>The code I have which won't compile (3 files, header, ADT implementation, main)
  How am I declaring the nested struct in struct array wrong?</p>
  
  <pre><code>// Defines the  cell.h ADT interface
  struct Cell;
  struct Cells;
  
  
  struct Cells {
      Cell cells[];
      int nCells;
     int capacity;
  };
  
  struct Cell {
     int location;
     int value;
  };
  
  //fill cells with random numbers
  void initialize(Cells *rcells);
  </code></pre>
  
  <p>ADT Implementation</p>
  
  <pre><code>using namespace std;
  
  #include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include "cell.h"
  
  void initialize(Cells *rcells){
      for(int i = 0 ; i &lt; rcells-&gt;nCells; i++)
     {
          rcells-&gt;cells[i].location = rand() % 100;
          rcells-&gt;cells[i].value = rand() % 1000;
      }
  }
  </code></pre>
  
  <p>main</p>
  
  <pre><code>using namespace std;
  
  #include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include "cell.h"
  
  int main(){
      Cells *c;
      c-&gt;cells[0].location=0;
      c-&gt;cells[0].value=0;
      c-&gt;cells[1].location=0;
      c-&gt;cells[1].value=0;
      c-&gt;nCells = 2;
      c-&gt;capacity = 2;
      initialize(c);
  }
  </code></pre>