Witam !
Otóż mam duży problem, ponieważ mam następujący kod funkcji w klasie:
int CreatureAI::addEmotions(ID3Byte ID, char* AJTA)
{
CreatureEmotions* emot = new CreatureEmotions();
allCreatureEmotions.push_back(emot);
allCreatureEmotions.back()->ID.ID = ID.ID;
allCreatureEmotions.back()->ID.IDType = ID.IDType;
for(int i = 0; i < 4; i++)
{
allCreatureEmotions.back()->AJTA[i] = *(AJTA + i);
}
return allCreatureEmotions.size() - 1;
}
allCreatureEmotions - std::list<struct CreatureEmotions*> allCreatureEmotions;
Creature Emotions:
struct CreatureEmotions
{
ID3Byte ID;
char AJTA[4];
};
ID3Byte
struct ID3Byte
{
unsigned int ID : 24;
unsigned int IDType : 8;
};
addEmotions, dlatego jest int, gdyż po dodaniu nowego wpisu emocji, funkcja ma zwrócić index tego wpisu.
Lecz gdy kompiluje i dodam tylko 1 wpis wszystko jest OK, ale gdy dodaje już drugi lub więcej na liście pojawiają się niestworzone wartości, a ich indexy wypisują mi się od końca (dodaje 1 element - daje mi index 1, jak dodaje 2 daje mi index 0). Dodam że musze operować na wzkaźnikach.
To jest funkcja, która wyświetla zawartość listy:
void CreatureAI::TESTshowAll()
{
for(unsigned int i = 0; i < allCreatureEmotions.size(); i++)
{
std::cout << "ID: " << (allCreatureEmotions.front() + i)->ID.ID
<< " ID Type: " << (allCreatureEmotions.front() + i)->ID.IDType
<< " AJTA: " << (int)(allCreatureEmotions.front() + i)->AJTA[0]
<< " " << (int)(allCreatureEmotions.front() + i)->AJTA[1]
<< " " << (int)(allCreatureEmotions.front() + i)->AJTA[2]
<< " " << (int)(allCreatureEmotions.front() + i)->AJTA[3];
std::cout << "\n";
}
std::cout << "\n\n";
}
Funcka Main, a właściwie jej kawałek:
CreatureAI cre;
char tob [5] = {1, 4, 2, 1, 6};
char tob2[4] = {1, 1, 1, 1};
char tob3[4] = {2, 2, 2, 5};
ID3Byte id;
id.ID = 25;
id.IDType = 7;
ID3Byte ido;
id.ID = 26;
id.IDType = 7;
std::cout << cre.addEmotions(id, tob) << " " << cre.addEmotions(id, tob2);
//<< " " << cre.addEmotions(ido, tob3) << "\n\n";
cre.TESTshowAll();
Proszę o szybką pomoc z góry dzięki!