Thanks KingMir! So it sounds like generally is a better idea to use references than pointers to pass arrays...
... but now I have a terrible new issue:
Nested iterators...? I don't even know how to describe my problem.
Declaration:
Code:
void Update(vector<Enemy*> &Enemies,
vector<Player*> &Players);
Called like so:
Code:
double GameLoopTimeLimit = 0.0166 * GameLoopTimeAdjust;
while (Game.IsOpened())
{
if (UpdateClock.GetElapsedTime() > GameLoopTimeLimit) {
for (vector<Actor*>::iterator it = Players.begin(); it != Players.end(); ++it)
{
GetInput(Game, it);
Update(Enemies, Players);
}
UpdateClock.Reset();
}
Render(Game, Camera, Players, Enemies);
}
ShutDown(Game);
return EXIT_SUCCESS;
}
Definition:
Code:
void Update(vector<Enemy*> &Enemies,
vector<Player*> &Players)
{
for (vector<Enemy*>::iterator itE = Enemies.begin(); itE != Enemies.end(); ++itE) {
for (vector<Player*>::iterator itP = Players.begin(); itP != Players.end(); ++itP) {
(*itE)->Update(*itP);
}
}
}
Errors:
Code:
/storage/Projects/Recent/Mon Oct 24/main.cpp||In function ‘int main()’:|
/storage/Projects/Recent/Mon Oct 24/main.cpp|121|error: invalid initialization of reference of type ‘std::vector<Enemy*>&’ from expression of type ‘std::vector<Actor*>’|
/storage/Projects/Recent/Mon Oct 24/main.cpp|59|error: in passing argument 1 of ‘void Update(std::vector<Enemy*>&, std::vector<Player*>&)’|
/storage/Projects/Recent/Mon Oct 24/main.cpp||In function ‘void Update(std::vector<Enemy*>&, std::vector<Player*>&)’:|
/storage/Projects/Recent/Mon Oct 24/main.cpp|139|error: no matching function for call to ‘Enemy::Update(Player*&)’|
/storage/Projects/Recent/Mon Oct 24/enemy.h|24|note: candidate is: void Enemy::Update(Actor&)|
||=== Build finished: 4 errors, 0 warnings ===|
I created this program from scratch, so... it's gonna be strange. What's going on here, is a Base Class <Actor> has been inherited by two child classes, <Enemy> and <Player> - there's 100 enemies and 1 player, but to leave open the chance for more players, I've handled both as vector<Actor*> for most of my program.
What this Update is trying to do is loop through all 100 enemies while checking a variable number of player objects each game loop. (*itE)->Update(*itP); is where it then calls the Update Function of the Current Enemy Object with the Current Player being fed into it (to check for distance from that player, between the two)
I've had it working, then failing, and this is the 5th incarnation of this function. I prolly need to call it a session and come back later.
As always, any insight = Awesome.
And, I get that I'm already IN a loop of players, and it's a little bit of a mess. I'd like to call Update with a Reference to a vector of <Enemy*> pointers, and simply feed it the current player as a 2nd argument. My logic has derailed a bit - I'll hit it up in a bit after some tea and a shower.
I'll get back with some working code within the day.