I am unable to understand the output of the following C++ snippet.
Should not objc.fn()
call A
's fn()
since B's fn()
is private
and should not be visible in C
. However, the answer is: the call to fn()
is ambiguous. How?
#include<iostream>
using namespace std;
class A{
public:
void fn() { cout << "1"; }
};
class B{
void fn() { cout << "2"; }
};
class C: public A, public B {};
int main(){
C objc;
objc.fn();
return 0;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…