如果某個(gè)派生類的部分或者全部直接基類是從另一個(gè)共同的基類派生而來(lái),在這些俄直接基類中,
從上一級(jí)基類繼承來(lái)的成員就擁有相同的名稱,因此派生類中就會(huì)出現(xiàn)同名現(xiàn)象。對(duì)這種類型的同名成員也要使用作用域分辨符來(lái)唯一標(biāo)識(shí),而且必須使用直接基類來(lái)進(jìn)行限定。
- --------------------------------------------------
- /*
- * 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;
- }