I am trying to assign an object to an array position. The position is given by an static variable (int) that contains the number of elements of the array. The size of tEntities is 5 and the size of fFuncionesList is 4, so it´s not a size problem.
if (TEntity::uEntityCount < 5)
{
iRandFuncList = rand() % (3 + 1);
iRandPosX = rand() % (120 + 1);
iRandPosY = rand() % (30 + 1);
tEntities[TEntity::uEntityCount] = new TEntity((fFuncionesList[iRandFuncList]), iRandPosX, iRandPosY);
}
TEntity(funcEntity *funcs, int x, int y)
{
m_ix = x;
m_iy = y;
m_funcs = funcs;
uEntityCount++;
}
I have tried to assign the value of the static variable to an int variable and it works, I would like to understand why it doesn't work with the static variable.
if (TEntity::uEntityCount < 5)
{
iRandFuncList = rand() % (3 + 1);
iRandPosX = rand() % (120 + 1);
iRandPosY = rand() % (30 + 1);
int pos = TEntity::uEntityCount;
tEntities[pos] = new TEntity((fFuncionesList[iRandFuncList]), iRandPosX, iRandPosY);
}
Thank you in advance.


fFuncionesList?I have tried to assign the value of the static variable to an int variable and it works, I would like to understand why it doesn't work with the static variable.- implies that your program's behavior is undefined, and adding another variable on the stak has changed its behavior (and coincidentally made it do what you wanted).tEntitiesis size 4, then do the math. Look at the picture you posted. Which slot are you indexing? Hint:tEntities[4]is the fifth element. Regardless, without a minimal reproducible example its all guesswork anyway. Best of luck.