#include<iostream>
using namespace std;
class Base
{
public:
virtual void show()
{
cout<<"this is Base show()"<<endl;
}
public:
Base()
{
cout<<"Create Base"<<endl;
}
//析构函数往往都是虚函数
virtual ~Base ()//记得个父类析构函数处加入 virtual 不然会造成内存泄漏
{
cout<<"free Base"<<endl;
}
};
class D:public Base
{
public:
void show()
{
cout<<"this is D show()"<<endl;
}
public:
D()
{
cout<<"Create D"<<endl;
}
~D()
{
cout<<"free D"<<endl;
}
};
void main()
{
Base *pb=new D;
delete pb;
}
//*一、多态
/*
class A
{
public:
virtual void Eat()
{
cout<<"A Eat()"<<endl;
}
virtual void Sleep()
{
cout<<"A Sleep()"<<endl;
}
};
class P : public A
{
public:
void Eat()
{
cout<<&#