I am recreating the classic Asteroids game from my childhood, and have run into a problem. Because of the frame rate, bullets pass through asteroids between frames. To fix this, I have a function that calculates the closest distance between each bullet and rock, called getClosestDistance. To problem I have is that the rocks are stored in a vector of pointers, and the bullets are in a vector of objects. All the classes I have are derived from a FlyingObjects class, so to pass an item of a class that is derived from FlyingObjects into another function, I would simply accept a FlyingObjects. Here is the prototype of getClosestDistanc:
Theoretically, this is how I should call it, right?
getClosestDistance(rock[i], bullets[i]);
However, I get the compile error:
game.cpp:181:58: error: no matching function for call to ‘Game::getClosestDistance(Rocks*&, Bullet&)’
if (getClosestDistance(rock[i], bullets[i]) < CLOSE_ENOUGH)
^
game.cpp:181:58: note: candidate is:
game.cpp:37:7: note: float Game::getClosestDistance(FlyingObject&, FlyingObject&) const
float Game :: getClosestDistance(FlyingObject &obj1, FlyingObject &obj2) const
^
game.cpp:37:7: note: no known conversion for argument 1 from ‘Rocks*’ to ‘FlyingObject&’
What can I do to fix this? Thanks a billion in advance!