一种错误的观念:
子类继承父类,只把父类的公有成员继承下来,私有的不会继承。
事实上无论是如何继承,都会把父类的所有成员继承下来。
1 #include<iostream> 2 using namespace std; 3 4 class Base { 5 private: 6 int x; 7 }; 8 9 class D :private Base{ 10 public: 11 int y; 12 }; 13 14 int main() 15 { 16 cout << sizeof(Base) << endl; 17 cout << sizeof(D) << endl; 18 return 0; 19 }