Hi,
I have a class that is inheriting from sf::Drawable and in the draw() pure virtual function that I am defining for this class I decided that I wanted to loop through a vector of objects and draw some sf::Text output by re-using the same member object and just changing the string, position, and then drawing it.
I soon ran into problems because the draw() function is declared as const.
void gui_table::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
// apply the transform
states.transform *= getTransform();
// draw the table background
target.draw(m_vertices);
// draw the column names
std::vector<column>::iterator itr;
for (itr = m_column_headers.begin(); itr != m_column_headers.end(); ++itr) {
m_text.setPosition(itr->rect.left + 5, itr->rect.top + 5);
m_text.setString(itr->value);
target.draw(m_text);
}
}
Severity Code Description Project File Line Suppression State
Error C2679 binary '=': no operator found which takes a right-hand operand of type 'std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<gui_table::column>>>' (or there is no acceptable conversion) Dark Ruins C:\Users\Erdrick\Documents\Visual Studio 2015\Projects\Dark Ruins\Dark Ruins\gui_table.cpp 64
This got me to thinking about why draw() is declared as const? I guess we should not expect to change things here, but I was thinking which of several approaches would be best.
1.) Should I be setting up a vector of sf::Text ahead of time to draw before i get to the draw() function?
2.) Should I make my own draw() function that is not const?
3.) Is there another recommended approach for what I am trying to do?