Overcoming diamond ambiguity in different way

江枫思渺然 提交于 2019-12-05 17:59:41

"Private members are not inherited" is a false premise, this isn't Java.

Member access in C++ was designed in such a way that if you replace any private: with public:, the behavior of the program will not change.

Because of that, name lookup, which occurs here when the compiler encounters the name "display" in d.display(), first locates all member functions in d with that name (there are two), then finds the best match (failure here), and only then checks if it happens to be inaccessible due to member access rules.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!