title: C++ - Class private variables not changing
body: <p>Ive been programming in C++ for a while and am using the SDL2 library to make a game. Unfortunately, the class for the player has variables that only change in the method and then don't update for later use.</p>
  
  <p>Header:</p>
  
  <pre><code>class playerChar {
  public:
       void move();
       void handleInput(SDL_Event&amp; lEvent);
       void render();
       int getValX();
       int getValY();
       playerChar();
  private:
       int pPosX, pPosY;             //Pos and Direction arent changing
       int pDirectionX, pDirectionY;
       //Posion and Direction (direction. Has value -1, 0 or 1)
       static const int pVel = 10;
       static const int pHeight = 10, pWidth = 10;
       eTexture playerTex;
  };
  </code></pre>
  
  <p>cpp file:</p>
  
  <pre><code>playerChar::playerChar(){
       pPosX = 0;
       pPosY = 0;
       pDirectionX = 0;
       pDirectionY = 0;
       playerTex.loadFile("playerIMG.png");
  }
  
  void playerChar::handleInput(SDL_Event&amp; lEvent){
       //Key Pressed
       if(lEvent.type == SDL_KEYDOWN &amp;&amp; lEvent.key.repeat == 0){
            switch(lEvent.key.keysym.sym){
                 case SDLK_UP:
                 pDirectionY = -1;
                 break;
                 case SDLK_s:
                 pDirectionY = 1;
                 printf("%i\n", pDirectionY);
                 break;
                 case SDLK_d:
                 pDirectionX = 1;
                 break;
                 case SDLK_a:
                 pDirectionX = -1;
                 break;
                 default:
                 break;
            }
       }
       //Key Released
       else if(lEvent.type == SDL_KEYUP &amp;&amp; lEvent.key.repeat == 0){
            switch(lEvent.key.keysym.sym){
                 case SDLK_w:
                 pDirectionY = 0;
                 break;
                 case SDLK_s:
                 pDirectionY = 0;
                 break;
                 case SDLK_d:
                 pDirectionX = 0;
                 break;
                 case SDLK_a:
                 pDirectionX = 0;
                 break;
                 default:
                 break;
            }
       }
  }
  
  void playerChar::move(){
       //printf("pos:%i, vel:%i, dir:%i\n", pPosY, pVel, pDirectionY);
       pPosX += pVel*pDirectionX;
       pPosY += pVel*pDirectionY;
       //If Direction is + then it adds velocity
       //If Direction is - then it subtracts
       //If Direction is 0 then adds nothing
       //printf("%i, %i\n", pDirectionX, pDirectionY);
  }
  
  void playerChar::render(){
       playerTex.render(pPosX, pPosY);
  }
  
  int playerChar::getValX(){
       return pDirectionX;
  }
  
  int playerChar::getValY(){
       return pDirectionY;
  }
  </code></pre>
  
  <p>Ive been checking the values of them with printf()s every frame (it is just a printf() in the main() that uses the getValX/Y() methods). The one inside of the handleInput() shows that it has changed in the method but then the one that runs every frame says that it is still 0. I mainly tested pressing s.</p>
  
  <p>Ive tried making the handleInput() method return the value and then making a set method but that didnt fix it.</p>
  
  <p>Ive looked over many websites and forums and an experienced friend who was also stumped and couldn't work out the problem. Any help is greatly appreciated. </p>
  
  <p><strong>Edit:</strong><br>
  Sorry if I am too vague, Im trying to keep it concise. The cpp above ONLY contains the methods for the playerChar class.<br>
  The actual implementation in Main() is</p>
  
  <pre><code>int main(int argc, char* args[]) {
  //irrevelvant to question
  
  playerChar player;
  while(!quit) {
            fpsTimer.start();
            quit = eInputCheck(event, player);
  
            if(fpsTimer.getTicks() &lt; ticksPerFrame) {
                 SDL_Delay(ticksPerFrame - fpsTimer.getTicks());
            }
            SDL_RenderClear(gRenderer);
  
            //Render new frame here
            player.move();
            player.render();
            printf("%ix, %iy\n", player.getValX(), player.getValY());
            SDL_RenderPresent(gRenderer);
       }
       eClose();
       return 0;
  }  
  </code></pre>
  
  <p>Where eInputCheck() is from controls.cpp</p>
  
  <pre><code>bool eInputCheck(SDL_Event event, playerChar player){
       while(SDL_PollEvent(&amp;event) != 0){
            player.handleInput(event);
            if(event.type == SDL_QUIT){
                 return true;
            }
       return false;
  }
  </code></pre>
  
  <p>I am trying to make it so that pDirectionX/Y change to 1 / -1 for direction and making 0 a standstill. The problem is that, even while holding the button down, it doesnt appear to change when I call the getValX/Y method in main.</p>
  
  <p>Terminal appears like so while running and I press s:</p>
  
  <pre><code>0x, 0y
  0x, 0y
  0x, 0y
  0x, 0y
  0x, 0y
  0x, 0y
  0x, 0y
  1        //The printf() from inside the handleInput() method
  0x, 0y
  0x, 0y
  0x, 0y
  0x, 0y
  </code></pre>
  
  <p>it even gives this while holding the button down. (I press ESC to end the program)</p>