#include <iostream>
using std::cout;
using std::endl;
class base {
public:
base()
{
cout<<"constructor of base class\n";
}
~base()
{
cout<<"destructor of base class\n";
}
virtual void say_hello(void)
{
cout<<"base say hello\n";
}
};
class child:public base {
public:
child(){
cout<<"constructor of child class\n";
}
~child(){
cout<<"destructor of child class\n";
}
virtual void say_hello(void)
{
cout<<"child say hello\n";
}
};
void say_hello(base *bp)
{
if (bp == NULL)
return;
bp->say_hello();
}
int main(int argc, char **argv)
{
base *bp = new child;
say_hello(bp);
delete bp;
bp = new base;
say_hello(bp);
delete bp;
bp = NULL;
return 0;
}