类成员函数的指针与多态性
#include"iostream"using namespace std;
class base
{
public:
virtual void print() { cout << "base" << endl; }
};
class derived :public base
{
public:
void print() { cout << "derived" << endl; }
};
void display(base *p, void(base::*pf)())
{
(p->*pf)();
}
int main()
{
derived d;
base b;
display(&d, &base::print);
display(&b, &base::print);
return 0;
}