object pointer as ROS message
Is it possible to pass an object pointer as a ROS message? Below a MWE, that doesn't even get to compile with error message:
talker.cpp:20:12: error: invalid conversion from ‘Foo*’ to ‘std_msgs::UInt64_<std::allocator<void> >::_data_type {aka long unsigned int}’ [-fpermissive]
msg.data = &foo;
^
MWE:
#include <iostream>
#include "ros/ros.h"
#include "std_msgs/UInt64.h"
class Foo
{
public:
int count;
};
int main(int argc, char **argv)
{
ros::init(argc, argv, "talker");
ros::NodeHandle n;
ros::Publisher chatter_pub = n.advertise<std_msgs::UInt64>("chatter", 1000);
ros::Rate loop_rate(10);
Foo foo;
foo.count = 0;
std_msgs::UInt64 msg;
msg.data = &foo;
while (ros::ok())
{
chatter_pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
++foo.count;
}
return 0;
}
Might be a silly question give that the pointer is of the object type pointer, but all I need to do is pass the integer hex memory address to another node (and hopefully create a same object pointer that points to the same address). Possibly, a dangerous thing to do but it will suffice. Any help appreciated.