嘿,我正在用c ++创建一个游戏作为学校项目,并试图从子类中获取父类的实例。我创建了一个类CollisionHandler,它可以作为回调或事件监听器。这工作到最近,但在我的代码发生一些变化之后,我再也无法让它工作了......这样做的正确方法是什么?
for (my $i=0;$i<scalar(@total);$i++)
{
print $d_quote . $total[$i] . $d_quote;
if ($i != (scalar(@total) - 1)) { print $comma; }
}
实现CollisionHandler的类:
class CollisionHandler{
public:
explicit CollisionHandler(){};
~CollisionHandler(){};
virtual Collision checkWorldCollision(sf::FloatRect playerPos);
virtual Collision checkPlayerCollision(sf::FloatRect attackPos);
};
然后我正在初始化一个使用Game作为CallbackHandler的类Player:
class Game : public CollisionHandler{
public:
Game();
~Game();
enum GameType{
TYPE_LOCAL,
TYPE_LAN
};
enum GameState{
PLAYING,
PAUSED,
ENDED
};
void initialize(int width, int height, Map map, GameType type);
void addPlayer(PlayerInfo& playerInfo, PlayerControls playerControls);
RunState start(sf::RenderWindow& window);
RunState resume(sf::RenderWindow& window);
void pause();
void exit();
Collision checkWorldCollision(sf::FloatRect playerPos);
Collision checkPlayerCollision(sf::FloatRect attackPos);
private:
RunState run(sf::RenderWindow& window);
GameState _currState;
World _world;
GameType _gameType;
std::vector<Player> _players;
int playerAmount;
};
直到最近一切正常,但是没有任何内容会影响这部分代码。得到此错误:
player.initialize(info, &game);
也出现此错误:
error: no matching function for call to ‘Player::initialize(PlayerInfo&, Game*)’
player.initialize(info, &game);
很抱歉所有的来回,但我已经将其缩小为声明错误,即使所有内容都包括在内: