2021年1月23日星期六

C++ remove by index a value within a vector of pointers

I'm trying to allow my code structure to just add and remove SDL_Textures* so that I don't have to manually add an offset or draw it, rather it all handled by my class Screen_Object. My declaration is std::vector < SDL_Texture* > m_Textures;. I have this other method that allows me to alter the std::vector but it won't compile:

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 );          }      }  }  

Here is the definitions btw:

std::vector < SDL_Texture* > m_Textures;  std::vector < SDL_Rect* > m_Texture_Rects;  

Error message:

error: no matching function for call to 'std::vector<SDL_Texture*>::erase(unsigned int&, int)'  
https://stackoverflow.com/questions/65866927/c-remove-by-index-a-value-within-a-vector-of-pointers January 24, 2021 at 11:39AM

没有评论:

发表评论