类和类的继承的简单使用

include using namespace std;
class Animal
{
public:

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

// cout <<"Animal construct"<
} ~Animal()//析构函数 {

// cout <<"Animal 析构函数 ^_^ " << endl;
} void eat() { cout <<"animal eat!" <

};
class fish : public Animal//继承
{
public:
fish() : Animal(400, 300), a(1)//析构函数,对a初始化 {

// cout <<"fish construct"<
} ~fish() {

【类和类的继承的简单使用】// cout <<"fish deconstruct"<
} 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;

}

    推荐阅读