Original Post
For a card game I have a vector defined in a superclass as follows
For loading and saving reasons I need to be able to get the id (index) of the pile from the array.
I made the following methods for this reason
For some strange reason I am getting id's that do not match those when the array is first created. There order has mysteriously changed. I have never experienced this before with a vector. I added the following method.
Just to print out the addresses. Here is the output when I first create it
And later on I print it out again
What the? The order has mysteriously changed. After its first creation I never modify the vector. How can this happen?
vector<Pile *> m_pileArray;For loading and saving reasons I need to be able to get the id (index) of the pile from the array.
I made the following methods for this reason
int GetPileId(Pile *pile) { for(int i=0; i<m_pileArray.size(); i++) if(m_pileArray == pile) return i; return -1; }
Pile *GetPileAddr(int id) { if(id == -1) return NULL; return m_pileArray[id]; }For some strange reason I am getting id's that do not match those when the array is first created. There order has mysteriously changed. I have never experienced this before with a vector. I added the following method.
void ListPiles() { for(int i=0; i<m_pileArray.size(); i++) DEBUGLOG("%02d %08x", i, m_pileArray); }Just to print out the addresses. Here is the output when I first create it
00 02278e04
01 02278e3c
02 02278e74
03 02278eac
04 02278ee4
05 02278f1c
06 02278f54
07 02278f8c
08 02278fc4
09 02278ffc
10 02279034
11 0227906c
12 022790a4And later on I print it out again
00 02278eac
01 02278e74
02 02278e04
03 02278e3c
04 02278ee4
05 02278f1c
06 02278f54
07 02278f8c
08 02278fc4
09 02278ffc
10 02279034
11 0227906c
12 022790a4What the? The order has mysteriously changed. After its first creation I never modify the vector. How can this happen?