【发布时间】: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