The two vectors contain pointers of base class actor, which are used to point to members of two derived classes (player and enemy) and polymorphically call the Update function from the current Enemy, with the current player as an argument.
I believe I have to use pointers, to allow polymorphism (though I read references could be used also, I'd love to be able to do that) since Player's Update function differs from Enemy's.
Code:
///////////////
// Game Loop //
///////////////
while (Game.IsOpened())
{
if (UpdateClock.GetElapsedTime() > GameLoopTimeLimit)
{
for (vector<Actor*>::iterator p_it = Players.begin(); p_it != Players.end(); ++p_it)
{
GetInput(Game, p_it);
for (vector<Actor*>::iterator e_it = Enemies.begin(); e_it != Enemies.end(); ++e_it)
{
*(e_it)->Update(p_it);
}
}
UpdateClock.Reset();
}
Render(Game, Camera, Players, Enemies);
}
The error I get is:
Code:
/storage/Projects/Recent/Refactored Game/src/main.cpp|156|error: request for member ‘Update’ in ‘* e_it.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator-> [with _Iterator = Actor**, _Container = std::vector<Actor*>, __gnu_cxx::__normal_iterator<_Iterator, _Container>::pointer = Actor**]()’, which is of non-class type ‘Actor*’|
I may not have explained the idea well, but basically a vector of pointers to Player is looped though, and for each player, each Enemy Pointer has it's Enemy Object's Update function run with the current player as an argument.
Any help fixing this code up would be wildly appreciated.
Edit:
I read through and realized I may not have made it clear what I want to do.
I want to call the appropriate Update function, of the Enemy Object, pointed to by e_it. If anyone can help me just decipher that error code, I can work on it myself. I really don't want or expect anyone to re-write my code for me.