函数覆盖只能发生在父类和子类之间
//继承
include
using namespace std;
class animal
{
public:
animal(int hight, int weight)
{
//cout << “animal construct” << endl;
}
~animal()
{
//cout << “animal deconstruct” << endl;
}
void eat()
{
cout << “animal eat” << endl;
}
void sleep()
{
cout << “animal sleep” << endl;
}
void breathe()
{
cout << “animal breathe” << endl;
}
};
class fish :public animal
{
public:
fish() : animal(400, 300),a(1)
{
//cout << "fish construct" << endl;
}
~fish()
{
//cout << "fish deconstruct" << endl;
}
void breathe()
//函数的覆盖,发生在父类和子类之间
//与父类中的breathe函数完全一样
{
animal::breathe();// :: 叫做作用域标识符,表示函数所属的类
cout << "fish bubble" << endl;
}
private:
const int a;
};
int main()
{
// animal an;
// an.eat();
fish fh;
fh.breathe();
// fh.sleep();
return 0;
}