c++ - Overcoming diamond ambiguity in different way -
I know the method of solving it using the diamond problem and the virtual base class. I tried to solve the diamond problem in a different way but did not succeed. I do not know why.
#include & lt; Iostream & gt; using namespace std; Class A {Public: Zero Exposure () {cout & lt; & Lt; "Successfully printed"; }}; Class B: Public A {}; Class C: Private A / Display () will be the personal member of AC {}; Class D: public B, public C / Private member's performance (should not be legacy of C) {}; Int main () {D d; D.display (); Return 0; } As the private members have not inherited, class D will not inherit any function, and when the succession of class D square B and C, there is only 1 demonstration ( ) Should be in the function D, but when I try to use the class D object using the display ()
function, it shows the same problem that the display function is ambiguous.
"Private members are not found" is a false base, it is not Java.
Membership access in C ++ was designed in such a way that if you change a private person: With the public: the behavior of the program will not change.
Because of this, the name lookup, which is here when the compiler has to face "display" in d.display (), then all member functions with the same name (there are two) , Then finds the best match (failure here), and only checks that the reason for the member access rules is due to being inaccessible.
Comments
Post a Comment