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

 

代码
#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呢?

 

posted @ 2010-12-20 09:34  嗷嗷  阅读(278)  评论(9编辑  收藏  举报