Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ array of structures initialization

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} };
like image 919
CodeKingPlusPlus Avatar asked Dec 13 '25 17:12

CodeKingPlusPlus


1 Answers

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

like image 130
Luchian Grigore Avatar answered Dec 16 '25 09:12

Luchian Grigore