#include "iostream.h"
class B
{
protected:
char* name;
public:
B()
{
name="Class B";
}
char* getName()
{
return name;
}
};
class D:public B
{
private:
int count;
public:
D()
{
name="Class D";
}
};
//*
void apply(B array[], int length,void (*f)(B&))
{
for(int i=0;i<length;i++)
f(array[i]);
}
//*/
//*
void apply(D array[], int length,void (*f)(D&))
{
for(int i=0;i<length;i++)
f(array[i]);
}
//*/
void somefunc(B& b)
{
cout<<"somefunc(B& b)"<<endl;
cout<<b.getName()<<endl;
}
void somefunc(D& b)
{
cout<<"somefunc(D& b)"<<endl;
cout<<b.getName()<<endl;
}
int main(int, char **)
{
D *dp=new D[3];
apply(dp,3,somefunc);
B *pb=new B[3];
apply(pb,3,somefunc);
return 0;
}