0

XmlRpc::XmlRpcValue を double 値にキャストしようとしています。暗黙的なキャスト方法は機能しなかったため、明示的にキャストする必要があります。ただし、3 つの明示的なキャスト タイプのいずれも動作させることができません。

XmlRpcValue は double のベクトルのベクトルです。.yaml ファイルでは、フィールドは次のようになります。

DOF: [[0, 3.5], [0, 3.5], [-3.14159, 3.14159]]

次に、各値を double に読み込みます。私は次のことを試しました:

for(unsigned int i=0;i<dof.size();i++) {
    double min = static_cast<double>(dof[i][0]);
    double max = static_cast<double>(dof[i][1]);
    //Do stuff

static_cast、reinterpret_cast、および dynamic_cast を使用します。明示的なカーストですべてを完全に理解しているとは思えませんが、必要なものは static_cast だと思います。何が起こるかを見るためだけに、ダイナミックと再解釈を試みました。それらはすべて、次のメッセージで失敗しました。

static - タイプ 'const XmlRpc::XmlRpcValue' からタイプ 'double' への無効な static_cast</p>

再解釈 - エラー: 型 'const XmlRpc::XmlRpcValue' から型 'double' への無効なキャスト</p>

動的 - dynamic_cast '(& dof.XmlRpc::XmlRpcValue::operator)->XmlRpc::XmlRpcValue::operator' ('const class XmlRpc::XmlRpcValue' 型) を 'double' 型 (ターゲットがポインターではないか、または参照)

誰かがこれで私を助けることができれば、私はそれを大いに感謝します.

編集:

std::vector< std::vector > に static_cast しようとしました。コンパイルに失敗しました:

~/my_path/main.cpp: In function ‘void setDOF(XmlRpc::XmlRpcValue)’:
~/my_path/main.cpp:64:97: error: conversion from ‘const XmlRpc::XmlRpcValue’ to ‘std::vector<std::vector<double> >::size_type {aka long unsigned int}’ is ambiguous
~/my_path/main.cpp:58:6: note: candidates are:
In file included from /opt/ros/hydro/include/ros/node_handle.h:51:0,
                 from /opt/ros/hydro/include/ros/ros.h:45,
                 from /home/sterlingm/ros_workspace/src/ramp/ramp_planner/src/main.cpp:1:
/opt/ros/hydro/include/XmlRpcValue.h:92:5: note: XmlRpc::XmlRpcValue::operator double&() <near match>
/opt/ros/hydro/include/XmlRpcValue.h:92:5: note:   no known conversion for implicit ‘this’ parameter from ‘const XmlRpc::XmlRpcValue*’ to ‘XmlRpc::XmlRpcValue*’
/opt/ros/hydro/include/XmlRpcValue.h:91:5: note: XmlRpc::XmlRpcValue::operator int&() <near match>
/opt/ros/hydro/include/XmlRpcValue.h:91:5: note:   no known conversion for implicit ‘this’ parameter from ‘const XmlRpc::XmlRpcValue*’ to ‘XmlRpc::XmlRpcValue*’
/opt/ros/hydro/include/XmlRpcValue.h:90:5: note: XmlRpc::XmlRpcValue::operator bool&() <near match>
/opt/ros/hydro/include/XmlRpcValue.h:90:5: note:   no known conversion for implicit ‘this’ parameter from ‘const XmlRpc::XmlRpcValue*’ to ‘XmlRpc::XmlRpcValue*’
In file included from /usr/include/c++/4.7/vector:65:0,
                 from /usr/include/boost/format.hpp:17,
                 from /usr/include/boost/math/policies/error_handling.hpp:30,
                 from /usr/include/boost/math/special_functions/round.hpp:14,
                 from /opt/ros/hydro/include/ros/time.h:58,
                 from /opt/ros/hydro/include/ros/ros.h:38,
                 from /home/sterlingm/ros_workspace/src/ramp/ramp_planner/src/main.cpp:1:
/usr/include/c++/4.7/bits/stl_vector.h:292:7: error:   initializing argument 1 of ‘std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const value_type&, const allocator_type&) [with _Tp = std::vector<double>; _Alloc = std::allocator<std::vector<double> >; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = std::vector<double>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<std::vector<double> >]’
make[2]: *** [ramp/ramp_planner/CMakeFiles/ramp_planner.dir/src/main.cpp.o] Error 1
4

1 に答える 1