C++ philosophy: Changing the accessibility of a class member should never change the meaning of a program.
2010-12-20 09:34
549 查看
代码
d.foo();这一行编译器会报错 error: "Dirived::foo" is ambiguous
那么既然,Bas2的foo是一个私有函数,在Dirived类中并不可见,为什么编译器还傻傻的说ambiguous呢?
#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呢?
相关文章推荐
- (NOT CLEAR)Question 44: What member function of std::fstream could a C++ developer invoke in order to change the target output f
- the memory of virtual base class of C++
- The Meaning of Class Definitions
- A c++ class wrapper to simplify the use of CRITICAL_SECTION and avoid dead-lock
- The Ruler To design Static Member of Class.
- Why is the size of an empty class not zero in C++?
- Networks of Innovation: Change and Meaning in the Age of the Internet
- An easy instance of using the template class in C++
- 【Size Classes Design Help】- Changing the Size or Position of a View for a Size Class
- Question 17: Which of the following identify const-correctness failures in the C++ program below?
- Question 38: What is the output of the program below in C++?
- get the runing time of C++ console program.
- How to change the text color of the selected property sheet tab in Visual C++
- Description of the default C and C++ libraries that a program will link with when built by using Vis
- [Linux] Touch--Change the time of files after changing your system time
- Class Hierarchies(Chapter 15 of The C++ Programming Language)
- EWB使用时出错-unable to write EWB program directory please change the permissions of this directory
- How to determine the size of a class/struct in the C++?
- How can I protect derived classes from breaking when I change the internal parts of the base class?