C++多繼承同名隱藏執行個體詳細介紹

來源:互聯網
上載者:User

如果某個衍生類別的部分或者全部直接基類是從另一個共同的基類派生而來,在這些俄直接基類中,
從上一級基類繼承來的成員就擁有相同的名稱,因此衍生類別中就會出現同名現象。對這種類型的同名成員也要使用範圍分辨符來唯一標識,而且必須使用直接基類來進行限定。
--------------------------------------------------
/*
* File: main.cpp
* Author: yubao
*
* Created on May 31, 2009, 8:54 AM
*/
#include <iostream>
using namespace std;
class B0
{
public :
int nV;
void fun(){cout<<"member of B0"<<endl;}
};
class B1:public B0
{
public:
int nV1;
};
class B2:public B0
{
public :
int nV2;
};
class D1:public B1,public B2
{
public:
int nVd;
void fun(){cout<<"member of D1"<<endl;}
};

/*
*
*/
int main(int argc, char** argv) {
D1 d1;
d1.B1::nV=2;
d1.B1::fun();
d1.B2::nV=3;
d1.B2::fun();
return 0;
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.