title: "The value is never used" pointer re-assignment C++
body: <p>I'm refactoring this bit of code:</p>
  <pre><code>struct GameState {
      PieceState piece;
  }
  
  
  //create local copy from piece, modify it, and only when its VALID copy it back!
  void update_game_play(GameState *game, const InputState *input) {
      PieceState piece = game-&gt;piece;
  
      //'left' from perspective of the game
      if (input-&gt;dleft &gt; 0) {
          --piece.offset_col;
      }
   
      if (is_piece_valid(&amp;piece, game-&gt;board, WIDTH, HEIGHT)) {
          game-&gt;piece = piece;
      }
  }
  </code></pre>
  <p>This code takes a <code>piece</code> struct, and only when it's valid it's re-assigned to the <code>GameState</code> struct.</p>
  <p>But in my refactored code the assignment gives me a warning that <code>the value is never used</code> in the last line, inside the if-statement:</p>
  <pre><code>    //create local copy from piece, modify it, and only when its VALID copy it back!
      void update(Piece *pieceTmp, Board *board) override
      {
          auto piece = *pieceTmp;
  
          //'left' from perspective of the game
          if (input.dleft &gt; 0) {
              --piece.offset_col;
          }
  
          //test with dummy if statement
          if (true) {
              pieceTmp = &amp;piece; //&quot;the value is never used&quot;
          }
  }
  </code></pre>
  <p>The way I understood it, is that I'm dereferencing the pointer to a object, changing the object properties, and then assign the address of the object to my original pointer? What's going on?</p>