标签:对象模型 mic 类继承 end std sizeof info 代码 main
我们知道继承方式有三种
public,protect,private
不同继承方式,在子类中有些是不可以访问的
那么我们想知道到底子类继承了多少?
看代码做一下验证
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 class father 5 { 6 public: 7 int a; 8 protected: 9 int b; 10 private: 11 int c; 12 }; 13 14 class son1:public father 15 { 16 public: 17 int d; 18 }; 19 20 class son2:protected father 21 { 22 public: 23 int d; 24 }; 25 26 class son3:private father 27 { 28 public: 29 int d; 30 }; 31 void test() 32 { 33 son1 s1; 34 cout << "size of s1 is " << sizeof(s1) << endl; 35 36 son2 s2; 37 cout << "size of s2 is " << sizeof(s2) << endl; 38 39 son3 s3; 40 cout << "size of s3 is " << sizeof(s3) << endl; 41 } 42 43 int main() 44 { 45 test(); 46 return 0; 47 }
无论何种继承都是16,也就是说父类的东西都继承下来了。只是有些访问权限
标签:对象模型 mic 类继承 end std sizeof info 代码 main
原文地址:https://www.cnblogs.com/mch5201314/p/11594007.html