C++ day6

1.

2.
 

#include 

using namespace std;

class Animal
{
private:
    string name;
public:
    virtual void perform()=0;
};
class Monkey:public Animal
{
private:
    string name;
public:
    void perform()
    {
        cout << "猴子偷桃" << endl;
    }
};
class Pig :public Animal
{
private:
    string name;
public:
    void perform()
    {
        cout << "猪拱白菜" << endl;
    }
};
class Duck :public Animal
{
private:
    string name;
public:
    void perform()
    {
        cout << "DUCK 不必" << endl;
    }
};
class Black_tiger :public Animal
{
private:
    string name;
public:
    void perform()
    {
        cout << "龙卷风摧毁停车场" << endl;
    }
};
int main()
{
    Pig p1;
    Monkey m1;
    Duck d1;
    Black_tiger af;
    Animal *p;

    p=&m1;
    p->perform();
    p=&p1;
    p->perform();
    p=&d1;
    p->perform();
    p=⁡
    p->perform();
    return 0;
}

你可能感兴趣的:(c++)