• c++ 初始化顺序


    class Base
    {
    public:
    	Base(int i) { cout << i; }
    	~Base() { }
    };
    class Base1: virtual public Base
    {
    public:
    	Base1(int i, int j=0) : Base(j) { cout << i; }
    	~Base1(){}
    };
    class Base2: virtual public Base
    {
    public:
    	Base2(int i, int j=0) : Base(j) { cout << i; }
    	~Base2(){}
    };
    class Derived : public Base2, public Base1
    {
    public:
    	Derived(int a, int b, int c, int d) : mem1(1), mem2(2), Base1(3),
    		Base2(4),Base(1)
    	{ cout << b; }
    private:
    	Base2 mem2;
    	Base1 mem1;
    };
    
    int main(int argc, char **argv)
    {
    	 Derived objD (1, 2, 3, 4); 
    
    
    	getchar();
    	return 0;
    }
    

      

    • 首先,任何虚拟基类的构造函数按照它们被继承的顺序构造;
    • 其次,任何非虚拟基类的构造函数按照它们被继承的顺序构造;
    • 最后,任何成员对象的构造函数按照它们声明的顺序调用;
  • 相关阅读:
    闭包 (Closure)
    RSA算法
    HTTPS
    SSH
    HDU1754 I hate it_线段树(入门级别)
    HDU1166 敌兵布阵_线段树
    c++运算符优先级表
    归并排序练习.
    HDU 1969 精度二分
    uva10944 状态压缩bfs or DP
  • 原文地址:https://www.cnblogs.com/kaishan1990/p/5567789.html
Copyright © 2020-2023  润新知