c++ - 该对象具有与覆盖 draw 的成员函数 sfml 不兼容的类型限定符

标签 c++ constants sfml

我正在使用 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?你还返回了 Sprite 的拷贝,这是你想要的吗?试试 const sf::Sprite& AnimatedSprite::getCurrent() const

关于c++ - 该对象具有与覆盖 draw 的成员函数 sfml 不兼容的类型限定符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26028374/

相关文章:

c++ - 为什么我的 SFML 游戏只能在终端中运行?

c++ - 使用 SFML 移动对象

c++ - 绘制 Sprite 导致 Segmentation Fault

c++ - "array bound is not an integer constant before ' ] ' token"使用多个文件时

c++ - 如何在缓冲区中读取和写入多个对象(或任何数据)?

c++ - 为什么 const 在 void/int 声明之后?

java - 如何使用枚举定义常量值组

c++ - 如何将版本号从git标记传输到CPack生成的源包?

python - 在 gdb 中运行混合 python/c++ 代码

c++ - 为什么可以从 const 引用调用析构函数?