(私は C++ にかなり慣れていないので、これが初歩的なミスであることを願っています)
コードに問題があり、いくつかの属性を必要とするクラス「Player」があり、抽象クラスを使用して属性を指定しようとしています。
//player.h
class Player : public IUpdate, public IPositionable, public IMoveable, public IDrawable
{
public:
Player(void);
SDL_Rect get_position();
void move(Uint32 dTime);
void update(Uint32 dTime);
void show(SDL_Surface* destination);
~Player(void);
private:
SDL_Surface texture;
int x, y;
};
そして、純粋仮想関数を次のようにオーバーライドしています。
//Player.cpp
Player::Player(void)
{
}
SDL_Rect Player::get_position()
{
SDL_Rect rect;
rect.h = 0;
return rect;
}
void Player::move(Uint32 dTime)
{
}
void Player::update(Uint32 dTime)
{
move(dTime);
}
void Player::show(SDL_Surface* destination)
{
apply_surface(x, y, &texture, destination, NULL);
}
Player::~Player(void)
{
}
ただし、コンパイルエラーが発生し続けます:C2259: 'Player' : cannot instantiate abstract class
私が見る限り、純粋な仮想関数をオーバーライドする必要があります。Google で検索したところ、Player は非抽象化されたはずですが、Player はまだ抽象化されているように見えます。
編集:純粋な仮想関数:
class IPositionable
{
public:
virtual SDL_Rect get_position() = 0;
private:
int posX, posY;
};
class IUpdate
{
public:
virtual void update (Uint32 dTime) = 0;
};
class IMoveable
{
public:
int velX, velY;
virtual void move(Uint32 dTime) = 0;
};
class IDrawable
{
public:
virtual void show() = 0;
private:
SDL_Surface texture;
};
class IHitbox
{
virtual void check_collsion() = 0;
};
class IAnimated
{
virtual void next_frame() = 0;
int state, frame;
int rows, columns;
};