我有2个主要的源文件。我需要将源1中的2个变量传递给源2。
变量将从kinect(x坐标,y坐标)中获取所需的值。具有来自kinect的不断变化的值的变量。它们将在源代码2上用于在rviz中将值作为ROS标记发布。
我打算使用带参数传递的Arguments的函数。从源1中的kinect中获取值,并将它们传递给将在源2中定义的函数。
我无法将值传递给源代码1中的函数。
下面显示了我的代码部分,我试图将值传递给我在源1.cpp中声明的m2fun()。
任何形式的帮助将不胜感激!
PS:我已经尝试声明外部变量y,z并希望从source1获取值并将其链接到源2但它不起作用..我按照here中的指示传递了参数参考
source1.cpp
float y1,z1,y,z; << global variable
float m2fun(float& y,float& z);
defined y = (value from kinect);
defined z = (another value from kinect);
//来自kinect的值来自静态函数();
int main(int argc, char** argv)
{
float y1 = y;
float z1 = z;
m2fun(y1,z1);
}
以下是编译后的错误..
/home/i2r/catkin_ws/src/kinect2_tracker/src/kinect2_tracker_node.cpp:65:7: error: ‘float y1’ redeclared as different kind of symbol
float y1,z1,y,z;
^
在/usr/include/features.h:374:0中包含的文件中,
from /usr/include/stdlib.h:24,
from /opt/ros/indigo/include/ros/platform.h:53,
from /opt/ros/indigo/include/ros/time.h:53,
from /opt/ros/indigo/include/ros/ros.h:38,
from /home/i2r/catkin_ws/src/kinect2_tracker/src/../include/kinect2_tracker.hpp:17,
from /home/i2r/catkin_ws/src/kinect2_tracker/src/kinect2_tracker_node.cpp:8:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:241:1: error: previous declaration of ‘double y1(double)’
__MATHCALL (y1,, (_Mdouble_));
^
make[2]: *** [kinect2_tracker/CMakeFiles/kinect2_tracker_node.dir/src/kinect2_tracker_node.cpp.o] Error 1
make[1]: *** [kinect2_tracker/CMakeFiles/kinect2_tracker_node.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j32 -l32" failed
答案 0 :(得分:0)
更改主要功能如下。
int main(int argc, char** argv)
{
//You are trying to redefine the variables z1 and y1
y1 = y;
z1 = z;`enter code here`
m2fun(y1,z1);
}