#include <stdio.h>
#include <Windows.h>
class Base
{
public:
Base() { printf("I am base !\n"); }
void play();
virtual void eat();
virtual ~Base() { printf("I am ~base !\n"); }
};
void Base::play()
{
printf("I am base play !\n");
}
void Base::eat()
{
printf("I am base eat !\n");
}
class Sun : public Base
{
public:
Sun() { printf("I am sun !\n"); }
~Sun() { printf("I am ~sun !\n"); }
void play();
void eat();
};
void Sun::play()
{
printf("I am sun play !\n");
}
void Sun::eat()
{
printf("I am sun eat !\n");
}
int main()
{
Base *b = new Base;
Base *p = new Sun;
Sun *s = new Sun;
b->play();
b->eat();
p->play();
p->eat();
s->play();
s->eat();
delete b;
delete p;
delete s;
b = NULL;
p = NULL;
s = NULL;
system("pause");
return 0;
}
输出结果: