title: C++ - Can you overload a function with different parameters but define it only once?
body: <p>I'm a beginner in c++ and I'm trying to make a simple command line game. I have three classes:</p>
  <pre><code>class DynamicEntity : public Entity { // Entity class has only int x, y variables and getters/setters
      protected:
          enum direction {RIGHT = 77, LEFT = 75, UP = 72, DOWN = 80};
      public:
          posWrap getNextPos(); // Returns the xy coordinates of the entity's next position in a struct called posWrap
  };
  
  class Player : public DynamicEntity {
      private:
          int wishdir;
      public:
          int ammoCount = 0;
          posWrap getNextPos(); // Same concept as above, but takes input
  };
  
  class CollisionHandler {
      public:
          static char checkCollisions(DynamicEntity&amp; dEntity); // Checks the next position of the entity for collisions and returns what it would collide with
          static char checkCollisions(Player&amp; player); 
  
  };
  
  </code></pre>
  <p>You see, I have overloaded the <code>checkCollisions</code> method. And defined the <code>DynamicEntity</code> version as such:</p>
  <pre><code>char CollisionHandler::checkCollisions(DynamicEntity&amp; dEntity) {
      int x = dEntity.getNextPos().x;
      int y = dEntity.getNextPos().y;
  
      return readChar(x, y);
  }
  </code></pre>
  <p>The implementation of the <code>getNextPos</code> functions are different for <code>Player</code> and <code>DynamicEntity</code>, as the first one takes an input from the player while the latter gets its orders from somewhere else in the program.
  I want to know if it is possible to pass in a <code>Player</code> class to <code>checkCollisions</code> and inside the method, use the <code>Player</code> version of <code>getNextPos</code>, without explicitly writing another definition of <code>checkCollisions</code>. I thought it would be possible since <code>Player</code> is a child of <code>DynamicEntity</code>. Or am I asking too much of the compiler?</p>
  <p>Let me know if you have any other suggestions, criticism or a better way to do this stuff. I am trying to learn more in-depth about these topics. Thanks in advance!</p>