#ifndef A_H
#define A_H
#include <iostream>
using namespace std;
class A
{
public:
A();
~A();
virtual int getNum();
virtual int getCount();
};
#endif
#include "a.h"
A::A()
{
}
A::~A()
{
}
int A::getNum()
{
cout<<"A:getNum"<<endl;
return 0;
}
int A::getCount()
{
cout<<"A:getCount"<<endl;
return 0;
}
#ifndef B_H
#define B_H
#include "a.h"
using namespace std;
class B:public A
{
public:
B();
~B();
virtual int getNum();
virtual int getCount();
};
#endif
#include "b.h"
B::B()
{
}
B::~B()
{
}
int B::getNum()
{
cout<<"B:getNum"<<endl;
return 0;
}
int B::getCount()
{
cout<<"B:getCount"<<endl;
return 0;
}
#include "b.h"
int main()
{
A *nameA = new B();
typedef int (A::*Funtion)();
Funtion arr[] =
{
&A::getCount,
&A::getNum
};
(nameA->*arr[0])();
(nameA->*arr[1])();
system("pause");
}
运行结果:
B:getCount
B:getNum
感觉这样就可以更加方便的管理子类中同种类型的函数了。