title: How to change an object's properties in another class' function in C++?
body: <p>I have a class called Object which has the following attributes: xPos and yPos. It also has getters and setters for these attributes. I have another class called CollisionDetector which has a function called detect that takes in two objects and detects if they have collided. If they have, then it pushes them away from each other using the setXPos() and setYPos() functions. However, it doesn't change the values and I'm trying to figure out why?</p>
  
  <pre><code>Object::Object(){
  
  }
  
  Object::Object(float x, float y) {  //constructor
      xPos = x;
      yPos = y;
  }
  
  float Object::getXPos(){
      return xPos;
  }
  
  float Object::getYPos(){
      return yPos;
  }
  
  void Object::setXPos(float temp){
      xPos = temp;
  }
  
  void Object::setYPos(float temp){
      yPos = temp;
  }
  
  char Object::getType(){
  return type;
  }
  
  bool CollisionDetector::detect(Object a, Object b){
      double size = 45; //Set size
      double xPosition = a.getXPos() - b.getXPos();
      double yPosition = a.getYPos() - b.getYPos();
      double sumRadius = (size/2 + 1) + (size/2 + 1);
      double radiusSquared = sumRadius * sumRadius;
      double distanceSquared = (xPosition * xPosition) + (yPosition * yPosition); //square the distances
  
      if (distanceSquared &lt;= radiusSquared)
      {
          //Check for collisions between tanks
          if(a.getType() == 't' &amp;&amp; b.getType() == 't'){
              if(a.getXPos() &gt; b.getXPos()){
                  a.setXPos(a.getXPos() + 10);
              }
              else if(a.getXPos() &lt; b.getXPos()){
                  a.setXPos(a.getXPos() - 10);
              }
              //Same for y direction
              if(a.getYPos() &gt; b.getYPos()){
                  a.setYPos(a.getYPos() + 10);
              }
              else if(a.getYPos() &lt; b.getYPos()){
                  a.setYPos(a.getYPos() - 10);
              }
          }
          return true;
      }
      return false;
  </code></pre>
  
  <p>}</p>
  
  <p>The function is called from main using:
  collisionDetector.detect(userTank, enemyTank);</p>