所以我遇到了一个问题,我已经为此奋斗了几个小时。 SO 上有各种各样的问题提示同一个问题,但没有适合我的解决方案..
我有两个结构
// \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;
};
我想像这样初始化它们:
static const JointPositions pos = {
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0}
};
return pos;
但是当我这样做时,我的编译器会报错如下:
RobotArm.cpp:59:2: error: could not convert ‘{0, 0}’ from ‘<brace-enclosed initializer list>’ to ‘JointPosition’
只要结构没有构造函数,Afaik 大括号初始化器就应该与结构一起工作。
我在 gcc 7.3 中使用 c++11。
感谢任何帮助。
这是演示该问题的在线链接:
最佳答案
关于c++ - 嵌套结构初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46624086/