主题:空虚函数的部分,忘高手指点一下
#include<iostream.h>
class base
{
public:
virtual void pirnt()
{cout<<"class base !\n";}
};
class son:public base
{
public:
virtual void print(){}
};
class grandson:public son
{
public:
virtual void print()
{cout<<"class grandson!\n";}
};
void show(base * p)
{
p->print();
}
void main()
{
base * pbase= new base;
son * pson=new son;
grandson * pgrandson=new grandson;
show(pbase);
show(pson);
show(pgrandson);
}
class base
{
public:
virtual void pirnt()
{cout<<"class base !\n";}
};
class son:public base
{
public:
virtual void print(){}
};
class grandson:public son
{
public:
virtual void print()
{cout<<"class grandson!\n";}
};
void show(base * p)
{
p->print();
}
void main()
{
base * pbase= new base;
son * pson=new son;
grandson * pgrandson=new grandson;
show(pbase);
show(pson);
show(pgrandson);
}