#include class Board; class Board { public: typedef void (Board::* B_MOVE)(unsigned); Board(unsigned x0, unsigned y0) : x(x0), y(y0){} void up (unsigned n = 1) { y += n; } void down (unsigned n = 1) { y -= n; } void left (unsigned n = 1) { x -= n; } void right(unsigned n = 1) { x += n; } void move(int m, B_MOVE h, int n, B_MOVE v); /* other members */ void display() { cout << x << " " << y << endl; } static const B_MOVE u; static const B_MOVE d; static const B_MOVE l; static const B_MOVE r; private: unsigned int x; // current x position unsigned int y; // current y position /* other members */ }; void Board::move(int m, B_MOVE h, int n, B_MOVE v) { (this->*h)(m); (this->*v)(n); } const Board::B_MOVE Board::u = &Board::up; const Board::B_MOVE Board::d = &Board::down; const Board::B_MOVE Board::l = &Board::left; const Board::B_MOVE Board::r = &Board::right; int main() { Board ab(7,10); ab.display(); ab.move(2, Board::u, 3, Board::r); // moves up 2 and right 3 ab.display(); }