标签:style blog http color strong div 2014 sp on
//以典型实例说明
1 class B1{}; 2 class V1:public B1(); 3 class D1:virtual public V1(); 4 class B2{}; 5 class B3{}; 6 class V2:public B1,publicB2{}; 7 class D2:virtual public V2,public B3{}; 8 class M1{}; 9 class M2{}; 10 class X:public D1,public D2 11 { 12 M1 m1_; 13 M2 m2_; 14 };
构造函数调用顺序:
1.首先,构造虚基类子对象;
构造V1: B1::B1() V1::V1()
构造V2: B1::B1() B2::B2() V2::V2()
2.其次,构造非虚基类子对象;
构造D1: D1::D1()
构造D2: B3::B3() D2::D2()
3.再次,构造所有成员: M1::M1() M2::M2()
4.最后,构造X本身X::X()
标签:style blog http color strong div 2014 sp on
原文地址:http://www.cnblogs.com/wanglei6261/p/3989475.html