我有一个名为“Game”的类,具有原型函数“Update”和“Draw”,但它们没有定义。由继承“游戏”对象的对象来覆盖它们。这可能吗?
“Game.h”的内容
class Game // does it have to abstract/virtual?
{
public:
//General stuff for all games here
}
void Update(Game *game) = 0; // or make it virtual in someway
“MyGame.h”的内容
#include "Game.h"
class MyGame : public Game
{
public:
// General stuff for my game
}
void Update(MyGame *game);
// “MyGame.cpp”的内容
#include "MyGame.h"
void Update(MyGame *game) // does it have to be overriden/overloaded?
{
}
// “GameManager.h”的内容
#include "Game.h"
class GameManager
{
public:
Game *game;
}
void Update(GameManager *manager);
// “GameManager.cpp”的内容
#include "Game.h"
void Update(GameManager *manager)
{
Update(manager->game);
}
关键是最后一个方法:为什么当GameManager的Game object = MyGame而不是Game时,GameManager不能调用MyGame Update()方法?