title: Can't change objects variable with objects function in C++
body: <p>Trying to create a graph of matrixes after changing one vertex of the matrix I add them to graph. Here is the code for it.</p>
  
  <pre><code>explicit Node(const State &amp;head) : head(head) {
      this-&gt;no_of_child = 0;
  }
  
  void AddChild(const State &amp;state){
  
      Node new_node(state);
      children.push_back(new_node);
      no_of_child = children.size();
  
  }
  
  void NextStates (){
      int n = head.getN();
      int ** matrix = head.getMatrix();
  
      //For all empty places in matrix create a new node if it meets the constraints.
      //Then add that node to the graph.
      for(int i = 0 ; i &lt; n ; i++) {
          for (int j = 0; j &lt; n; j++) {
  
              if(matrix[i][j] == 0){
                  matrix[i][j] = 2;
  
                  State child(n, matrix, head.getRows(), head.getCols());
                  if(child.isLegal()){
                      AddChild(child);
  
                      cout&lt;&lt;"========================================="&lt;&lt;endl;
                      children[no_of_child-1].getHead().printState();
                  }
                  matrix[i][j] = 0;
              }
  
          }
      }
  
      cout&lt;&lt;"=========================================\n"
            "========================================="&lt;&lt;endl;
      for(int i = 0 ; i &lt; no_of_child ; i++) {
          children[i].getHead().printState();
          cout&lt;&lt;"========================================="&lt;&lt;endl;
      }
  
  }
  </code></pre>
  
  <p>First <code>printState()</code> prints exactly what I want.
  But after the loop ends second <code>printState()</code> prints matrix but nothing has changed. First I see it changed but then it is just a bunch of copy of my initial matrix. I couldn't even make a comment on this. Please help.</p>