Background info: Me and a couple of friends are building this platform game in C++ with the help och sfml and box2d for a school assignment. One of the requirements is that we follow the "MVC pattern".
We have created classes like Bullet and Character for the model. And BulletView and CharacterView (both inherits sf::Drawable which is an abstract class) for the view.
Instead of duplicating code for drawing and have two methods drawBullets and drawCharacter like this
void WorldView::drawBullets()
{
std::vector<BulletView*>::iterator it;
for ( it = bullets.begin() ; it < bullets.end(); it++ )
window->draw(**it);
}
void WorldView::drawCharacters()
{
std::vector<CharacterView*>::iterator it;
for ( it = characters.begin() ; it < characters.end(); it++ )
window->draw(*it);
}
I would like a more generic method using polymorhism which would look something like this:
void WorldView::drawVector(const std::vector<sf::Drawable*>& vector)
{
std::vector<sf::Drawable*>::iterator it;
for ( it = vector.begin() ; it < vector.end(); it++ )
window->draw(**it);
}
The bulletView vector is declared like this:
std::vector<BulletView*> bullets;
Can't get this to work though. And I'm kind of new to C++ so please have mercy! I've tried searching but have not found very specific answers.
Errors I get while compiling.
Error 8 error C2679: binary '=' : no operator found which takes a right-hand >operand of type 'std::_Vector_const_iterator<_Myvec>' (or there is no acceptable >conversion) c:\users\niklas\multiplaya\sfml test\sfml test\view\worldview.cpp 409 >1 SFML_Test
Error 7 error C2664: 'mp::WorldView::drawVector' : cannot convert parameter 1 from >'std::vector<_Ty>' to 'const std::vector<_Ty> &' c:\users\niklas\multiplaya\sfml >test\sfml test\view\worldview.cpp 402 1 SFML_Test