I have a menu class, which contains a vector of buttons (another class). Each button also has assigned to it a pointer to a member function of the menu class (the effect of the button). These are then called according to which button is clicked / pressed. But I can't seem to manage to call the member functions from the pointers correctly (code won't compile).
Here's the menu class showing relevant bits:
class cMenu {
private:
void display();
void addButton(string text, mePointer mePtr);
bool doButton(vector<button>::const_iterator bi);
void meNewGame();
void meLoadGame();
void meSettings();
void meReturn();
void meQuit();
vector<button> mButtons;
};
and here's relevant parts of the button class with the typedef, to make valid pointers to the cMenu::meFoos():
typedef void (cMenu::*mePointer)();
class button {
public:
friend class cMenu;
private:
string text;
mePointer mePtr;
};
Buttons are added to the array like so:
addButton("Return", &cMenu::meReturn);
void cMenu::addButton(string text, mePointer mePtr) {
button temp;
SDL_Color c;
temp.text = text;
temp.mePtr = mePtr;
mButtons.push_back(temp);
}
//and for ref
void cMenu::meReturn() {
menu.finish();
}
I try to call the pointed to functions like so:
void cMenu::display() {
for (vector<button>::const_iterator i=mButtons.begin(); i!=mButtons.end(); ++i) {
if (doButton(i))
(i->*mePtr)();
}
}
This gives me the compiler error that "`mePtr' undeclared (first use this function) ". I've tried messing around with the call, but I can't seem to get it right.
Am I doing something fundamentally wrong here?
[Edited by - Windhawk on December 14, 2006 9:21:51 PM]