zoukankan      html  css  js  c++  java
  • 虚基类的sizeof

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26

    class A
    {

    };
    class B : virtual public A
    {
     
    };
    class C : virtual public A
    {
     
    };
    class D : public B, public C
    {
     
    };
     
    int main(void)
    {
        cout << sizeof(A) << endl; //1
        cout << sizeof(B) << endl; //4
        cout << sizeof(C) << endl; //4
        cout << sizeof(D) << endl; //8
     
        return 0;
    }
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26

    class A
    {
        int a;
    };
    class B : virtual public A
    {
     
    };
    class C : virtual public A
    {
     
    };
    class D : public B, public C
    {
     
    };
     
    int main(void)
    {
        cout << sizeof(A) << endl; //4
        cout << sizeof(B) << endl; //8
        cout << sizeof(C) << endl; //8
        cout << sizeof(D) << endl; //12 A的int 4Byte,B C虚继承指针4+4,共12Byte.
     
        return 0;
    }
  • 相关阅读:
    JavaScript事件详解
    JavaScript事件
    十六进制转十进制原理
    java:数组复制
    java:数组扩容
    MySQL---Day2
    Pyhton学习——Day47
    MySQL---Day1
    Pyhton学习——Day46
    Someing-About-Work
  • 原文地址:https://www.cnblogs.com/helloweworld/p/3135218.html
Copyright © 2011-2022 走看看