【问题标题】:the object has type qualifiers that are not compatible with the member function sfml overriding draw对象具有与覆盖 draw 的成员函数 sfml 不兼容的类型限定符
【发布时间】:2014-09-24 23:55:43
【问题描述】:

我正在使用 SFML 2.1 并且想要覆盖 drawable::draw 方法:

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

在其实现中,我使用具有以下签名的成员函数:(导致标题错误的函数)

const sf::Sprite AnimatedSprite::getCurrent()

在这个函数中,我使用了另一个具有类似签名的函数:

const sf::Sprite Animation::getCurrent()

我返回一个非常量的 Sprite。

我想这可能是问题所在,但为什么呢?我不能使用非常量变量来绘制我的实体吗?如果可以,怎么做?

【问题讨论】:

  • 你忘了在 getCurrent 函数上添加 const 吗?您还返回了精灵的副本,这是您的意图吗?试试const sf::Sprite& AnimatedSprite::getCurrent() const
  • 它正在工作,编辑它作为答案:D

标签: c++ constants sfml


【解决方案1】:

您是否忘记在 getCurrent 函数上添加 const?您还返回了精灵的副本,这是您的意图吗?试试const sf::Sprite& AnimatedSprite::getCurrent() const

【讨论】:

    猜你喜欢
    • 2014-08-31
    • 2016-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    • 2012-02-16
    相关资源
    最近更新 更多