Hi there,
I am encountering a very annoying issue, and I couldn't find any solution knowing that my problem is rather .. uncommon. I need to iterate througn a vector in a const function, and, as my function is called very often, to get more performances I need my iterator to be declared somewhere else than the function, so it doesn't have to get deleted and recreated over and over again. So here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
class Shop
{
public:
//methods
virtual void draw(sf::RenderTarget &target, sf::RenderStates states) const //The function i'm talking about
{
//things
for(m_cit = m_buttonList.begin(); m_cit != m_buttonList.end(); ++m_cit)//m_buttonlist is a std::vector
{
//things
}
}
private:
std::vector<MenuButton*>::const_iterator m_cit; // the iterator, member of the class
};
|
Seems great, huh? Well no. I actually get an error on the "for" line.
It tells me : "You can't use '=' here" and "You can't use the ++ operator here"
The thing is, if I actually declare my iterator in the loop, the compiler stops giving me warnings, but, as I said, I really want to avoid doing that.
Thanks for reading and as always thanks for your help!