9月4号作业

#include 
 
  
using namespace std;
 
  
class an
{
private:
    string name;
public:
    an(){}
    an(string na):name(na)
    {}
    virtual void fun()=0;
};
 
  
 
  
class lion : public an
{
private:
    string name;
public:
    lion(){}
    lion(string na,string na2):an(na2),name(na)
    {}
    void fun()
    {
        cout << "name= " << name < 
  
    }
};
 
  
 
  
class tiger : public an
{
private:
    string name;
public:
    tiger(){}
    tiger(string na,string na2):an(na2),name(na)
    {}
    void fun()
    {
        cout << "name= " << name < 
  
    }
};
 
  
 
  
int main()
{
    tiger a("老虎","动物");
     lion b("狮子","动物");
    an *p=&a;
    p->fun();
    p=&b;
    p->fun();
 
  
    return 0;
}

9月4号作业_第1张图片

 
 

你可能感兴趣的:(算法)