【发布时间】:2021-01-24 03:39:48
【问题描述】:
我试图让我的代码结构只添加和删除SDL_Textures*,这样我就不必手动添加偏移量或绘制它,而是由我的类Screen_Object 处理。我的声明是std::vector < SDL_Texture* > m_Textures;。我有其他方法可以让我更改 std::vector 但它不会编译:
void Screen_Object::Remove_Texture(SDL_Texture* p_Texture)
{
for (unsigned int i=0; i < m_Textures.size(); i++)
{
if (m_Textures[i] == p_Texture)
{
m_Textures.erase(i, 1 );
m_Texture_Rects.erase(i, 1 );
}
}
}
顺便说一句,这里是定义:
std::vector < SDL_Texture* > m_Textures;
std::vector < SDL_Rect* > m_Texture_Rects;
错误信息:
error: no matching function for call to 'std::vector<SDL_Texture*>::erase(unsigned int&, int)'
【问题讨论】:
-
请每个 stackoverflow.com 问题一个问题。你问的是两个完全不同的问题,彼此毫无关系。
-
好吧,最后一部分对
const很有意义。我不太确定我是否理解关于擦除的第一部分,例如“将向量的索引转换为等效的迭代器”