參考博客:http://blog.csdn.net/hexi_2000/article/details/4392107
成都創(chuàng)新互聯(lián)公司是一家專業(yè)提供金溪企業(yè)網(wǎng)站建設(shè),專注與網(wǎng)站制作、網(wǎng)站設(shè)計、成都h5網(wǎng)站建設(shè)、小程序制作等業(yè)務(wù)。10年已為金溪眾多企業(yè)、政府機構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(jìn)行中。
//重載,覆蓋,隱藏舉例 #include <iostream> using namespace std; class A { public: int n; void fun() { cout<<"A::fun()"<<endl; } virtual void fun(int a) { cout<<"A::fun(int)"<<endl; } void fun(double f) { cout<<"A::fun(double)"<<endl; } }; class B:public A { public: int n; void fun(int a) { cout<<"B::fun(int)"<<endl; } void fun(double f) { cout<<"B::fun(double)"<<endl; } }; int main(int argc, char *argv[]) { A a; B b; A *p; p=&b; p->fun(); p->fun(20); p->fun(19.9); b.fun(19.9); b.n=5; cout<<b.A::n<<endl; return 0; }
網(wǎng)站標(biāo)題:C++重載、覆蓋、隱藏的區(qū)別與舉例
標(biāo)題URL:http://www.chinadenli.net/article12/gcipdc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機、網(wǎng)站制作、標(biāo)簽優(yōu)化、關(guān)鍵詞優(yōu)化、微信公眾號、網(wǎng)站設(shè)計公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)