When developing in ROS, you may encounter the “error: request for member ‘__getDataType’ in ‘m’, which is of non-class type” error, with an example call stack below:
In file included from /opt/ros/indigo/include/ros/serialization.h:37:0,
from /opt/ros/indigo/include/ros/publisher.h:34,
from /opt/ros/indigo/include/ros/node_handle.h:32,
from /opt/ros/indigo/include/ros/ros.h:45,
from /home/turtlebot/workspace/door_ws/src/door-help/include/door_help/follower.hpp:6,
from /home/turtlebot/workspace/door_ws/src/door-help/src/follower.cpp:11:
/opt/ros/indigo/include/ros/message_traits.h: In instantiation of ‘static const char* ros::message_traits::MD5Sum<M>::value(const M&) [with M = float]’:
/opt/ros/indigo/include/ros/message_traits.h:255:104:   required from ‘const char* ros::message_traits::md5sum(const M&) [with M = float]’
/opt/ros/indigo/include/ros/publisher.h:112:7:   required from ‘void ros::Publisher::publish(const M&) const [with M = float]’
/home/turtlebot/workspace/door_ws/src/door-help/src/follower.cpp:81:20:   required from here
/opt/ros/indigo/include/ros/message_traits.h:126:34: error: request for member ‘__getMD5Sum’ in ‘m’, which is of non-class type ‘const float’
return m.__getMD5Sum().c_str();
^
/opt/ros/indigo/include/ros/message_traits.h: In instantiation of ‘static const char* ros::message_traits::DataType<M>::value(const M&) [with M = float]’:
/opt/ros/indigo/include/ros/message_traits.h:264:106:   required from ‘const char* ros::message_traits::datatype(const M&) [with M = float]’
/opt/ros/indigo/include/ros/publisher.h:112:7:   required from ‘void ros::Publisher::publish(const M&) const [with M = float]’
/home/turtlebot/workspace/door_ws/src/door-help/src/follower.cpp:81:20:   required from here
/opt/ros/indigo/include/ros/message_traits.h:143:36: error: request for member ‘__getDataType’ in ‘m’, which is of non-class type ‘const float’
return m.__getDataType().c_str();
So why did you get the: request for member ‘__getDataType’ in ‘m’, which is of non-class type error?
This error will occur if there is a difference between the type of the object you are attempting to publish, and the type of the object you have advertised. For example, if you advertise:
 
pub_ = n_.advertise&lt;std_msgs::<wbr />Float64&gt;("custom/heading", 10);

And then in code try to publish:

Looking to get a head start on your next software interview? Pickup a copy of the best book to prepare: Cracking The Coding Interview!

Buy Now On Amazon
 
float x = 10;
pub_.publish(x);
This will produce the error, because the type being published (float) does not match the type advertised (std_msgs::Float64).
The solution is ensure the published type matches the type advertised:
 
std_msgs::Float64 msg;
msg.data = 10;
pub_.publish(msg)

Contact Us