B
Bob Altman
Hi all,
I have two C++ structures. Both structures include a parameterless
constructor that initializes the structure members. These two structures
define different ways of looking at the same data; one structure exposes the
data as an array of bytes, the other exposes the bytes as individual
structure members. However, because of the constructors, I can't create a
higher-level struct that unions the two structures together. (The
structures in a union can not have a user-supplied default constructor.)
So, here's my question: If I have an instance of one structure type, is
there a way to tell C++ to treat it as though it is an instance of the other
structure type without having to create an overloaded "=" operator that
moves bytes in memory? The reinterpret_cast operator would seem to be just
what I want, but it refuses to cast one type to a totally unrelated type.
TIA - Bob
I have two C++ structures. Both structures include a parameterless
constructor that initializes the structure members. These two structures
define different ways of looking at the same data; one structure exposes the
data as an array of bytes, the other exposes the bytes as individual
structure members. However, because of the constructors, I can't create a
higher-level struct that unions the two structures together. (The
structures in a union can not have a user-supplied default constructor.)
So, here's my question: If I have an instance of one structure type, is
there a way to tell C++ to treat it as though it is an instance of the other
structure type without having to create an overloaded "=" operator that
moves bytes in memory? The reinterpret_cast operator would seem to be just
what I want, but it refuses to cast one type to a totally unrelated type.
TIA - Bob