How to write a callback function for Int8Multiarray messages subscription
I wrote a callback function for subscription for a int8Multiarray type array:
void arrayCallback(const std_msgs::Int8MultiArray::ConstPtr& array)
{
int i = 0;
int* p = array->data;
for (i = 0; i < 10; i++)
{
std::cout << array[i] << std::endl;
}
return;
}
However, I cannot build the source code with this callback (I am positive that this is the only place that is causing error). The error in the prompt is:
/home/turtlebot/test2/src/GraphSub.cpp: In function ‘void arrayCallback(const boost::shared_ptr<const std_msgs::Int8MultiArray_<std::allocator<void> > >&)’:
/home/turtlebot/test2/src/GraphSub.cpp:12: error: cannot convert ‘const std::vector<signed char, std::allocator<signed char> >’ to ‘int*’ in initialization
/home/turtlebot/test2/src/GraphSub.cpp:15: error: no match for ‘operator[]’ in ‘array[i]’
Could anyone help me to eyeball the error?