3

I have the following structure:

struct localframepos
{
    double ipos; //local room frame i(x) coordinate, in mm
    double cpos; //local room frame c(y) coordinate, in mm
    double rpos; //local room frame r(z) coordinate, in mm

    localframepos()
    {
        ipos = 0;
        cpos = 0;
        rpos = 0;
    }
    localframepos(double init_ipos, double init_cpos, double init_rpos) //init constructor
    {
        ipos = init_ipos;
        cpos = init_cpos;
        rpos = init_rpos;
    } 
};

How do I get the following functionality:

localframepos positions[] = { {0, .5, .2},
                              {4.5, 4, .5} };

3 Answers 3

3

Remove the constructors. To use curly brace initialization, the type has to be a POD.

Sign up to request clarification or add additional context in comments.

4 Comments

Why C++11, this is simple aggregate initialization.
@CodeKingPlusPlus Plain Old Data
@JesseGood does C++03 support intializing arrays with pod's?
-1 "To use curly brace initialization, the type has to be a POD." is incorrect for C++03 (any aggregate can be initialized with curly braces syntax), and it is even more incorrect for C++11.
0

I usually use

localframepos positions[] = { localframepos(0  , .5, .2),
                              localframepos(4.5, 4, .5) };

which is not that nice looking, but much more flexible if you need different initialization possibilities.

Comments

0

For C++03 you can write

localframepos positions[] = { localframepos( 0, .5, .2 ),
                              localframepos( 4.5, 4, .5 ) };

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.