Reinterpreting a union to a different union

后端 未结 4 953
时光说笑
时光说笑 2021-02-01 15:16

I have a standard-layout union that has a whole bunch of types in it:

union Big {
    Hdr h;

    A a;
    B b;
    C c;
    D d;
    E e;
    F f;
};

4条回答
  •  猫巷女王i
    2021-02-01 15:29

    I can find no wording in n4296 (draft C++14 standard) which would make this legal. What is more, I cannot even find any wording that given:

    union Big2 {
        Hdr h;
    
        A a;
        B b;
        C c;
        D d;
        E e;
        F f;
    };
    

    we can reinterpret_cast a reference to Big into a reference to Big2 and then use the reference. (Note that Big and Big2 are layout-compatible.)

提交回复
热议问题