C++ union array and vars?

mpen picture mpen · Mar 31, 2009 · Viewed 22.1k times · Source

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

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

Where x == v[0] and y == v[1]?

Answer

Brian R. Bondy picture Brian R. Bondy · Mar 31, 2009

Since you are using C++ and not C, and since they are of the same types, why not just make x a reference to v[0] and y a reference to v[1]