example
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <functional>
#include <string>
typedef void(*handler)(const char*);
class A {
protected:
typedef void(A::*handler)(const char* b);
public:
handler a;
A() {
a = &A::foo;
}
void foo(const char* a) {
std::cout<< "foo "<< std::string(a) << std::endl;
}
};
class B : public A {
public:
B() : A() {
a = (handler)&B::f1;
}
void f1(const char* a) {
std::cout<< "f1 "<< std::string(a) << std::endl;
}
};
int main()
{
A a1;
a1.foo("hello");
B b;
b.f1("hello");
A* ap = &a1;
(ap->*(ap->a))("world");
(a1.*(a1.a))("wold");
(b.*(b.a))("wold");
}
foo hello
f1 hello
foo world
foo wold
f1 wold