//Listing 14.11 Array of pointers to member functions #include using namespace std; class Dog { public: void speak()const { cout << "Woof!\n"; } void move() const { cout << "Walking to heel...\n"; } void eat() const { cout << "Gobbling food...\n"; } void growl() const { cout << "Grrrrr\n"; } void whimper() const { cout << "Whining noises...\n"; } void rollOver() const { cout << "Rolling over...\n"; } void playDead() const { cout << "Is this the end of Little Caeser?\n"; } }; typedef void (Dog::*PDF)() const; int main() { const int MAX_FUNCS = 7; PDF DogFunctions[MAX_FUNCS] = { &Dog::speak, &Dog::move, &Dog::eat, &Dog::growl, &Dog::whimper, &Dog::rollOver, &Dog::playDead }; Dog* pDog = 0; int method; bool fQuit = false; while (!fQuit) { cout << "(0)Quit (1)speak (2)move (3)eat (4)growl"; cout << " (5)whimper (6)Roll Over (7)Play Dead: "; cin >> method; if (method == 0) { fQuit = true; break; } else { pDog = new Dog; (pDog->*DogFunctions[method-1])(); delete pDog; } } return 0; }