Fw: [C++-sig] Pyste and STL types
Nicodemus
nicodemus at globalite.com.br
Wed Mar 19 02:58:37 CET 2003
David Abrahams wrote:
>Nicodemus <nicodemus at globalite.com.br> writes:
>
>
>>What do you mean by "active field"? I ask because my knowledge of
>>unions is limited.
>>
>
>The one someone stored data in.
>
I know, but from your comment I understood that C/C++ took care of this
for you, like this:
union Test
{
float d;
int i;
};
void main()
{
Test t;
t = 3.0; // use the d member
float x = t; // get the d member
t = 1; // set the i member
int z = t; // get the i member
}
Which I don't think is the case. The programmer has to take care of what
field is active:
void main()
{
Test t;
t.d = 3.0; // set the d member
int z = t.i; // member i has garbage
float x = t.d; // ok
}
What am I missing?
More information about the Cplusplus-sig
mailing list