I am trying to Iterate over a vector using pointers. I have a vector:
std::vector<GameObject*> objects;
and loads of such functions:
void Game::update()
{
std::vector<GameObject*>::iterator itr;
for( itr = objects.begin();itr < objects.end();++itr)
{
itr->update();
}
}
Game::~Game()
{
delete ball;
delete player;
}
Game::Game()
{
ball = new GOBall(800/2 - GOBall::SIZE/2,600/2 - GOBall::SIZE/2);
player = new GOPlayer(0, 600/2 - GOPlayer::SIZEY/2,ball);
objects.push_back(ball);
objects.push_back(player);
}
As you can see, I am trying to iterate in such a way that it still allows me to call the function, as well as parse the polymorphic class in other polymorphic classes (therefore, the reason it is declared before being parsed into a vector), which I keep getting is an error :
C2839: Invalid return type 'GameObject * const *' for overloaded 'statement →'
and error:
C2039: 'update': is not a member of 'std :: _ Vector_const_iterator <_Ty, _Alloc>'
which tells me that I cannot call ball->update()either player->update()through an iterator, so how to do this?