我正在尝试使用Allegro 4进行游戏编码,而且我遇到了一个奇怪的碰撞。链接器在我的两个类中声明了对析构函数的未定义引用,但我没有做任何事情。可能是什么问题?这是我的代码:
Entity.h:
#pragma once
#include <allegro.h>
struct Rectangle
{
int x;
int y;
int w;
int h;
};
typedef enum {
FACE,
POOP
} EntityType;
class Entity
{
private:
EntityType m_EntityType;
BITMAP *m_Sprite;
int m_Score;
int m_X;
int m_Y;
Rectangle *m_Hitbox;
public:
Entity();
virtual ~Entity() {destroy_bitmap(m_Sprite);}
BITMAP *GetSprite() {return m_Sprite;}
int GetScore() {return m_Score;}
int GetX() {return m_X;}
int GetY() {return m_Y;}
Rectangle GetHitbox() {return *m_Hitbox;}
void SetSprite(EntityType type);
void SetScore(int value) {m_Score = value;}
void SetX(int value) {m_X = value;}
void SetY(int value) {m_Y = value;}
void SetHitbox(EntityType type);
};
Entity.cpp:
#include "Entity.h"
void Entity::SetSprite(EntityType type)
{
if (type == FACE)
m_Sprite = load_bitmap("face.bmp", NULL);
else if (type == POOP)
m_Sprite = load_bitmap("poop.bmp", NULL);
}
void Entity::SetHitbox(EntityType type)
{
if (type == FACE)
{
GetHitbox().x = m_X;
GetHitbox().y = m_Y;
GetHitbox().w = m_X + 32;
GetHitbox().h = m_Y + 32;
}
else if (type == POOP)
{
GetHitbox().x = m_X;
GetHitbox().y = m_Y;
GetHitbox().w = m_X + 16;
GetHitbox().h = m_Y + 16;
}
}