그래서 몇 시간 동안 계속해서 논쟁을 벌여 왔습니다. 이 같은 문제에 대해 불평하지만 솔루션은 나를 위해 작동하지 SO에 대한 다양한 질문 ..중첩 구조체 초기화
2 구조체
// \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;
};
내가 한 수 있습니다 그리고 나는이처럼 initialze 지탱하려면 :
내가 그렇게 할 때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을 사용하고 있습니다.
도움을 주시면 감사하겠습니다.
https://onlinegdb.com/HkKzwoLhb
@VittorioRomeo 아니요 6 개의 JointPosition을 가진 단일 JointPositions를 만들고 싶습니다. –
@Someprogrammerdude 문제를 시연하는 onlinegdb에 대한 링크를 추가했습니다. –
제공하는 링크는 "C++"라고만 말합니다. "C++ 14". 보통 C++ 03이라는 것을 의미합니다. 그러나'JointPosition'에서 인라인 초기화를 제거하면 오류없이 컴파일해야하며 (C++이 개발 된 이후와 C에서 그 전에 구현 된 적이있다) 컴파일해야합니다. –