标签:类型转换 指针 扩展 ++ 功能 ges style main ons
继承过程中构造函数调用顺序:基类构造函数——>派生类中对象构造函数——>派生类构造函数体 class A { public: A() :a(1) { cout<<"A()"<<endl; cout<<a<<endl; } void fun() { cout<<"A-fun()"<<endl; } ~A() { cout<<"~A()"<<endl; } private: int a; }; class B:public A { public: B() { cout<<"B()"<<endl; } void fun() { cout<<"B-fun1()"<<endl; } ~B() { cout<<"~B()"<<endl; } private: int b; }; int main() { A a; B b; return 0; }
(4).赋值兼容规则
class A { public: int a; private: int a1; }; class B:public A { public: int b; private: int b1; }; class C:public A { public: int c; private: int c1; }; class D:public B,public C { public: int d; private: int d1; }; int main() { cout<<sizeof(A)<<endl;//8 cout<<sizeof(B)<<endl;//16 cout<<sizeof(C)<<endl;//16 cout<<sizeof(D)<<endl;//40 将a a1保存了两份 D d; d.a=3; //产生对a访问的二义性 d.C::a / d.B::a return 0; } ***虚承继的情况:由于涉及到虚函数表和虚基表,会同时增加一个(多重虚继承下对应多个)vfPtr指针指向虚函数表vfTable和一个vbPtr指针指向虚基表vbTable,这两者所占的空间大小为:8(或8乘以多继承时父类的个数);
用虚继承解决菱形继承的二义性和数据冗余问题
标签:类型转换 指针 扩展 ++ 功能 ges style main ons
原文地址:http://www.cnblogs.com/JN-PDD/p/6639336.html