#include <iostream>
#include <memory>
class animal
{
public:
animal() = default;
virtual ~animal() {}
virtual void eat() { std::cout << "animal eat!"<<std::endl; }
};
class bird : public animal
{
public:
bird() = default;
virtual void eat() {std::cout<< "bird eat!" << std::endl; }
};
int main()
{
// 最老的 new / delete 父类指针指向子类
//animal* p_animal;
//p_animal = new bird;
//p_animal->eat();
//delete p_animal;
// share_ptr / new
//std::shared_ptr<animal> p_animal(new animal);
//p_animal->eat();
// share_ptr / make_ptr 调用自己
//std::shared_ptr<animal> p_animal;
//p_animal = std::make_shared<animal>();
//p_animal->eat();
// share_ptr / make_ptr 父类指针指向子类
std::shared_ptr<animal> p_animal;
p_animal = std::make_shared<bird>();
p_animal->eat();
return 0;
}