0
爲什麼我無法實例化?爲什麼玩家是抽象類? 我是否僅在基類中聲明純虛函數?錯誤錯誤C2259:'玩家':無法實例化抽象類
class Object
{
protected:
public:
virtual void DrawOnScreen() = 0;
};
class Creature : public Object
{
public:
virtual void DrawOnScreen()=0;
virtual void Eat(Object*)=0;
virtual void move(Direction)=0;
};
class Player : public Creature
{
void Player::DrawOnScreen()
{
cout << "position= (" << get_x() << "," << get_y() << ")" << endl << "player's score " << points << endl;
if (get_isKilled()) cout << "It is Killed " << endl;
else cout << "It is Alive " << endl;
}
void Player::eat(Object* p)
{
Point* chk;
chk = dynamic_cast<Point*>(p);
if ((chk != 0) && (get_x() == chk->get_x()) && (get_y() == chk->get_y()) && (chk - > get_isExist()))
{
points = points + chk->get_weight();
chk->set_isExist(false);
}
}
void Player::move(Direction d)
{
if (d == UP)
{
y = y + 2;
}
if (d == DOWN)
{
y = y - 2;
}
if (d == RIGHT)
{
x = x + 2;
}
if (d == LEFT)
{
x = x - 2;
}
}
}
我敢肯定,錯誤消息列出了確實純粹的功能,你沒有覆蓋RESP。沒有執行。 – Deduplicator
C++區分大小寫。寫吃飯和大寫搬家 – slfan
@slfan:移動是可編譯的,儘管不一致。它不會與std :: move衝突。 – lpapp