C++ union array and vars?

前端 未结 8 1460
日久生厌
日久生厌 2021-02-19 22:18

There\'s no way to do something like this, in C++ is there?

union {
    {
        Scalar x, y;
    }
    Scalar v[2];
};

Where x == v[0]<

8条回答
  •  别那么骄傲
    2021-02-19 22:38

    How about

    union {
        struct {
            int x;
            int y;
        };
        int v[2];
    };
    

    edit:

    union a {
        struct b { int first, second; } bee;
        int v[2];
    };
    

    Ugly, but that's more accurate

提交回复
热议问题