2 zzy zhangzeyu Zzy_ZhangZeyu_ 于 2014.12.11 12:55 提问

派生类对象如何访问基类的基类中被隐藏的同名函数成员
#include <iostream>

using namespace std;

class Base0{
public:
    int var0;
    void Func(){ cout << "This is Func of Base0" << endl; }
};

class Base1:public Base0{
public:
    int var1;
    void Func(){ cout << "This is Func of Base1" << endl; }
};

class Base2:public Base0{
public:
    int var1;
    void Func(){ cout << "This is Func of Base2" << endl; }
};

class Derived:public Base1, public Base2{
public:
    int var;
    void Func(){ cout << "This is Func of Derived" << endl; }
};

int main(void)
{
    Derived dest;
    dest.Func();
    dest.Base1::Func();
//  dest.Base0::Func();     //ERROR
    return 0;
} 

我把问题改的复杂了一点
现在Derived类中有Base0::Func()的两个副本,我想访问从Base1继承来的Base0::Func()该如何操作呢

3个回答

piaobotudou
piaobotudou   2014.12.11 15:37

dest.Base0::Func();

wangxugangzy05
wangxugangzy05   2014.12.11 15:40

dest.Base0::Func(); // it's ok

nanjian011
nanjian011   2014.12.11 15:58

dest.Base0::Func();

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!