a一级爱做片免费观看欧美,久久国产一区二区,日本一二三区免费,久草视频手机在线观看

新聞中心

EEPW首頁 > 嵌入式系統 > 設計應用 > C++函數的覆蓋與再現例子

C++函數的覆蓋與再現例子

作者: 時間:2016-12-01 來源:網絡 收藏
/**********************
子類覆蓋基類某個函數的方法是定義子類之后在子類重新聲明
子類要將要覆蓋的這個函數,記得要聲明!比如本例中①處eat()之前不能
省略void。在子類②處在寫法還可以重載基類eat()函數。
************************/
#include
class animal
{
public:
eat();
};
animal::eat()
{
cout<<"我是基類的eat()"<
}
class pig:public animal
{
public:
void eat(); // ①
};
void pig::eat()
{
animal::eat(); //②
cout<<"我是pig類的eat(),我覆蓋了基類animal的eat()"<
}
int main()
{
pig stp;
stp.eat();
}


關鍵詞: C++函數覆蓋與再

評論


相關推薦

技術專區

關閉