您的位置:首页 > 编程语言 > C语言/C++

C++ philosophy: Changing the accessibility of a class member should never change the meaning of a program.

2010-12-20 09:34 549 查看
代码

#include <iostream>
using std::cout;
using std::endl;
class Base1{
public:
void foo(){cout<< "Base1::foo"<<endl;};
};

class Base2{
private:
void foo(){cout<< "Base1::foo"<<endl;};
};

class Dirived : public Base1,public Base2{};

int main(){
Dirived d;
d.foo();
return 0;
}


d.foo();这一行编译器会报错 error: "Dirived::foo" is ambiguous

那么既然,Bas2的foo是一个私有函数,在Dirived类中并不可见,为什么编译器还傻傻的说ambiguous呢?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: