#include <iostream>
#include <functional>

using namespace std;

class Test {
  std::function<int(Test*)> func;
public:
  int operator()() {  return func(this); }

  int DoIt1() {
    return 1;
  }

  int DoIt2() {
    return 2;
  }

  void SetIt(int i) {
    if(i == 1) {
      func = &Test::DoIt1;
    } else {
      func = &Test::DoIt2;
    }
  }
};

int main()
{
  Test t1;

  t1.SetIt(1);

  std::cout << t1() << std::endl;

  t1.SetIt(2);

  std::cout << t1() << std::endl;

  return 0;
}