关于fetch:类和类的继承的简单使用

4次阅读

共计 706 个字符,预计需要花费 2 分钟才能阅读完成。

include <iostream>

using namespace std;

class Animal

{
public:

 Animal(int heigh, int weight)// 构造函数
{

// cout <<“Animal construct”<<endl;

}
 ~Animal()// 析构函数
{

// cout <<“Animal 析构函数 ^_^ ” << endl;

}
 void eat()
 {cout <<"animal eat!" <<endl;}

 void sleep()
 {cout <<"animal sleep!" <<endl;}
 void breakthe()
 {cout <<"animal breakthe!" <<endl;}

};

class fish : public Animal// 继承
{
public:

 fish() : Animal(400, 300), a(1)// 析构函数,对 a 初始化
{

// cout <<“fish construct”<<endl;

}
 ~fish()
 {

// cout <<“fish deconstruct”<<endl;

}
 void breakthe()
 {

// Animal :: breakthe();// 拜访 Animal 类中的 breaktne() 函数

    cout << "fish bublle ^_^" << endl;
 }

private:

 const int a;

};

void fn(Animal *pAn)

{

 fish *fi;
 cout << &pAn << endl;
 cout << &fi << endl;
 fi->breakthe();
 pAn->breakthe();

}
int main()

{

 Animal an(3, 5);
 Animal *pAn;
 fish fi;

 pAn = &fi;
 fn(pAn);
 return 0; 

}

正文完
 0