继承适用于一个类,但不适用于另一个类

时间:2017-06-04 09:18:48

标签: c++ inheritance sfml

我创建了两个类:Player,Bullet。两者都继承自相同的SFML类sf::Drawable和sf :: Transformable。

头等舱:

class Player :
    public sf::Drawable, sf::Transformable
{
public:
    Player();
    ~Player();

    enum Direction {UP, DOWN, LEFT, RIGHT};

    void update();
    void move(Direction dir);
    float getRotation();
    sf::Vector2f getPosition();
    void shoot();
    bool moveStatus;

private:
    sf::Sprite sprite;
    sf::Texture texture;

    float speed;
    size_t frame;

    sf::Clock animClock;
    sf::Clock shootTime;

    virtual void draw(sf::RenderTarget &target, sf::RenderStates states) const;
};

第二课:

class Bullet :
    public sf::Drawable, sf::Transformable
{
public:
    Bullet(float rot, sf::Vector2f pos);
    ~Bullet();

    void update();
    float getRotation();
    sf::Vector2f getPosition();
    void move(float x, float y);

private:
    sf::Sprite sprite;
    sf::Texture texture;

    virtual void draw(sf::RenderTarget &target, sf::RenderStates states) const;
};

我对virtual void draw(sf::RenderTarget &target, sf::RenderStates states) const;有疑问。在Player类中,它正在工作,但在Bullet类中却没有。

链接器返回2个错误:
enter image description here
我试图在states之前将“&”添加到定义中,但随后Bullet变成了一个抽象类。

1 个答案:

答案 0 :(得分:0)

您的问题是,您错过了draw课程中Bullet方法的实际实施

没有代码,很难说,但你要么完全错过它,要么签名中可能有拼写错误。

相关问题