samedi 7 octobre 2017

Nested struct initialization

So I have an issue I have been battling for a couple hours. There are a variety of questions on SO that complain about the same issue but no solutions work for me..

I have 2 structs

// \brief The state of a single joint position. Default value of the speed is the maximum it wil allow.
struct JointPosition
{
    /// \brief The degree to set the joint to.
    double degree = 0;
    /// \brief The max degrees per second it will allow during the move.
    double maxDegreesPerSecond = 0;
};

/// \brief Struct containing all joint positions as degrees.
struct JointPositions
{
    JointPosition base;
    JointPosition shoulder;
    JointPosition elbow;
    JointPosition wrist;
    JointPosition gripper;
    JointPosition wristRotate;
};

And I want to brace initialze them like this:

static const JointPositions pos = {
    {0, 0},
    {0, 0},
    {0, 0},
    {0, 0},
    {0, 0},
    {0, 0}
};

return pos;

But when I do so my compiler complains with the following error:

RobotArm.cpp:59:2: error: could not convert ‘{0, 0}’ from ‘<brace-enclosed initializer list>’ to ‘JointPosition’

Afaik brace initializers should work with structs as long as they don't have a constructor.

I am using c++11 with gcc 7.3.

Any help is appreciated.

Here is an online link demonstrating the issue:

http://ift.tt/2xppBfm

Aucun commentaire:

Enregistrer un commentaire