• Create Account

### #Actualstitchs

Posted 21 July 2012 - 04:25 AM

I did notice one thing, which I don't think has been picked up on here yet (apologies if it has). The below portion of your code:

if((*it)->getState())
{
delete *it;
it = enemyVector.erase(it);
}

What does getState() return, I am assuming a boolean for the moment as you say it cycles through and deletes everything until it errors on the last element. What are you checking getState() against because, if it is a boolean, then it will erase every time that getState() returns true, which may be what you want if it only represents ALIVE as being true or false, which in any case should be checked against a second boolean attribute, for clarity. Also, the naming of the method seems ambiguous, and may lose meaning when you go away and come back to the code at a later date.

If it is a numerical data type, like an Integer, then it will delete an enemy every time the loop is called, as once the 'State' is initialised, it will always evaluate to true. The only time, to my knowledge, that this isn't the case is when the 'State' is either not initialised (this will lead to a runtime check failure), or initialised to NULL or 0 (this will prevent the conditional check from evaluating true). In every other case, whether 'State' is 1 or -9999, this will always lead to your delete code being run, which could lead to some if not all of your enemies 'dying' prematurely.

I hope this is of help,

Regards,

Stitchs.

### #1stitchs

Posted 21 July 2012 - 04:23 AM

I did notice one thing, which I don't think has been picked up on here yet (apologies if it has). The below portion of your code:

if((*it)->getState())
{
delete *it;
it = enemyVector.erase(it);
}

What does getState() return, I am assuming a boolean for the moment as you say it cycles through and deletes everything until it errors on the last element. What are you checking getState() against because, if it is a boolean, then it will erase every time that getState() returns true, which may be what you want, but the naming of the method seems ambiguous, and may lose meaning when you go away and come back to the code at a later date.

If it is a numerical data type, like an Integer, then it will delete an enemy every time the loop is called, as once the 'State' is initialised, it will always evaluate to true. The only time, to my knowledge, that this isn't the case is when the 'State' is either not initialised (this will lead to a runtime check failure), or initialised to NULL or 0 (this will prevent the conditional check from evaluating true). In every other case, whether 'State' is 1 or -9999, this will always lead to your delete code being run, which could lead to some if not all of your enemies 'dying' prematurely.

I hope this is of help,

Regards,

Stitchs.

PARTNERS