From: James Kanze on
On Jan 1, 3:55 pm, Peng Yu <pengyu...(a)gmail.com> wrote:
> union is inherited from C. But since C++ has reinterpret_cast,
> I'm wondering when union would be useful in a pure C++
> program. Or union is just for backward compatibility. Could
> somebody give some examples on when to use union and when to
> use reinterpret_cast?

It depends on what you are trying to do. Unions are the
standard means of "overlaying" different data, in order to save
space. In C++, this doesn't always work as well as we'd like,
since most useful types can't be members of a union.
reinterpret_cast is designed to fill a completely different
need, that of type punning. In practice, reinterpret_cast
should only be used for very low level work.

--
James Kanze

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]