I have a static vector of SessionMenu pointers defined in SessionMenu.h as follows:
static vector<SessionMenu *> sessionMenus;
I have defined an accountType enum in the SessionMenu class, and initialise this variable in the constructor of the SessionMenu class.
In the entry point of my application, I add three objects to this vector as follows:
SessionMenu::sessionMenus.push_back(&StudentSessionMenu());
SessionMenu::sessionMenus.push_back(&TutorSessionMenu());
SessionMenu::sessionMenus.push_back(&AdministratorSessionMenu());
At this point, when I debug the SessionMenu::sessionMenus at this point, the pointers are valid and the value of the accountType variable is as expected.
However, later in my application when I iterate over the vector my pointers as so:
for (vector<SessionMenu *>::iterator menuIterator = sessionMenus.begin();
menuIterator != sessionMenus.end(); ++menuIterator) {
SessionMenu *currentMenu = *menuIterator;
if(currentMenu->getAccountType() == accountType)
return currentMenu;
}
return NULL;
The pointers seem to be pointing somewhere different.
Any ideas what could be causing this?
Cheers.