Array of objects with vector as class member
<p>I have an array of objects that have a vector as a class member (actually it is a struct). The struct is:</p>

<pre><code>struct Cell {
  vector&lt;int&gt; borderNodes;
  vector&lt;int&gt; helperNodes;

  int minNodePointer;
  int maxNodePointer;


  Cell() {
    minNodePointer = -1;
    maxNodePointer = -1;
  }

  Cell(int _minNodePointer, int _maxNodePointer) {
    minNodePointer = _minNodePointer;
    maxNodePointer = _maxNodePointer;
  }

  vector&lt;int&gt;&amp; getHelperNodes() {
    return helperNodes;
  }

  vector&lt;int&gt;&amp; getBorderNodes()  {
    return borderNodes;
  }

  void setHelperNodesArray() {
    sort(helperNodes.begin(), helperNodes.end());
  }

  void setBorderNodesArray() {
    sort(borderNodes.begin(), borderNodes.end());
  }
}; 
</code></pre>

<p>I have built an array of those objects as a global variable with :</p>

<pre><code>Cell* cells = new Cell[maxNumberOfCells];
</code></pre>

<p>and I want to add some integers to the vectors inside the objects.</p>

<p>I tried this (inside a function):</p>

<pre><code>cells[cellId].borderNodes.push_back(node_id);
</code></pre>

<p>or </p>

<pre><code>cells[cellId].getBorderNodes().push_back(node_id);
</code></pre>

<p>and they compile fine, but nothing is added to the vector. How is the correct way to do this? Here is the function that reads from a db, and adds the integers. The query and reading from db is correct, so no mistakes there.</p>

<pre><code>void loadBorderNodesPerCellBnOnly(bool shouldRearrangeNodes, int subtractor, int maxNumberOfCells, int** cellBorderNodes) {
    cellBorderNodes = new int*[maxNumberOfCells];
    try {
        work W(Conn);
        for (int rownum = 0; rownum &lt; r.size(); ++rownum) {
            const result::tuple row = r[rownum];

            vector&lt;string&gt; s = split(row[1].as&lt;string &gt; (), ' ');
            const int mySize = s.size();
            int cellId = row[0].as&lt;int&gt; ();
            cellBorderNodes[cellId] = new int[mySize];
            for (int k = 0; k &lt; mySize; k++) {
                int node_id = atoi(s[k].c_str());
                cellBorderNodes[cellId][k] = node_id;
                (cells[cellId].getBorderNodes()).push_back(node_id);
                try {
                    nodes[node_id - subtractor].cellId = cellId;
                } catch (const std::exception &amp;e) {
                    std::cerr &lt;&lt; e.what() &lt;&lt; std::endl;
                }
                nodes[node_id - subtractor].isBorderNode = true;
            }
            s.clear();
        }
    } catch (const std::exception &amp;e) {
        std::cerr &lt;&lt; e.what() &lt;&lt; std::endl;
    }


    for (int k = 0; k &lt; maxNumberOfCells; k++) {
        cout &lt;&lt; k &lt;&lt; ": " &lt;&lt; cells[k].borderNodes.size() &lt;&lt; endl;
        cells[k].setBorderNodesArray();
        if (maxBorderNodesPerCell &lt; cells[k].borderNodes.size()) {
            maxBorderNodesPerCell = cells[k].borderNodes.size();
        }
    }
}
</code></pre>
