【发布时间】:2011-11-04 19:14:32
【问题描述】:
我很困惑为什么 C++ 编译器不接受这个:
class Foo {
private: void Baz() { }
};
class Bar {
public: void Baz() {
};
class FooBar : public Foo, public Bar { };
void main() {
FooBar fb;
fb.Baz();
}
gcc 给出的错误是:
request for member ‘Baz’ is ambiguous
candidates are: void Bar::Baz()
void Foo::Baz()
但是我想要 Bar::Baz() 不是很明显吗,因为 Foo::Baz() 是私有的?为什么编译器不会在这里消除歧义?
【问题讨论】:
标签: c++ inheritance multiple-inheritance