When pre-defining a structure using a union, how to tell compiler what element to place the value into?

Consider this code:

>struct MyStruct
>{
>    union
>    {
>        int i;
>        float f;
>    } value;
>};
>
>
>MyStruct Values[] =
>{
>    300L,
>    10.0f,
>    15.0f,
>}

Now the 10.0f, and the 15.0f values are converted to integer, and placed into the union. How, if possible, to make them remain as floats and then placed into the union. I tried using a void * in the union as the first field, but the compiler wont convert floats to void *.
VectreAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

n_fortynineCommented:
check this out (the anonymous union part)
http://www.cplusplus.com/doc/tutorial/tut3-6.html
0
VectreAuthor Commented:
Anonymous union or not, the values still are converted to the first type in the union.

0
AlexFMCommented:
struct MyStruct
{
    MyStruct(float f)
    {
        value.f = f;
    }

    MyStruct(long i)
    {
        value.i = i;
    }

    union
    {
        int i;
        float f;
    } value;
};
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VectreAuthor Commented:
Guess one's screwed in regular C eh?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.